diff options
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 28 |
2 files changed, 29 insertions, 1 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 63a67e0..4f31793 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -7238,7 +7238,7 @@ void QGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) */ void QGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if (flags() & ItemIsSelectable) { + if (event->button() == Qt::LeftButton && (flags() & ItemIsSelectable)) { bool multiSelect = (event->modifiers() & Qt::ControlModifier) != 0; if (event->scenePos() == event->buttonDownScenePos(Qt::LeftButton)) { // The item didn't move diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 15ae53a..2637106 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -478,6 +478,7 @@ private slots: void QTBUG_13473_sceneposchange(); void QTBUG_16374_crashInDestructor(); void QTBUG_20699_focusScopeCrash(); + void QTBUG_30990_rightClickSelection(); private: QList<QGraphicsItem *> paintedItems; @@ -11497,5 +11498,32 @@ void tst_QGraphicsItem::QTBUG_20699_focusScopeCrash() fs.setFocus(); } +void tst_QGraphicsItem::QTBUG_30990_rightClickSelection() +{ + QGraphicsScene scene; + QGraphicsItem *item1 = scene.addRect(10, 10, 10, 10); + item1->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable); + QGraphicsItem *item2 = scene.addRect(100, 100, 10, 10); + item2->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable); + + // right mouse press & release over an item should not make it selected + sendMousePress(&scene, item1->boundingRect().center(), Qt::RightButton); + QVERIFY(!item1->isSelected()); + sendMouseRelease(&scene, item1->boundingRect().center(), Qt::RightButton); + QVERIFY(!item1->isSelected()); + + // right mouse press over one item, moving over another item, + // and then releasing should make neither of the items selected + sendMousePress(&scene, item1->boundingRect().center(), Qt::RightButton); + QVERIFY(!item1->isSelected()); + QVERIFY(!item2->isSelected()); + sendMouseMove(&scene, item2->boundingRect().center(), Qt::RightButton); + QVERIFY(!item1->isSelected()); + QVERIFY(!item2->isSelected()); + sendMouseRelease(&scene, item2->boundingRect().center(), Qt::RightButton); + QVERIFY(!item1->isSelected()); + QVERIFY(!item2->isSelected()); +} + QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" |