Details
-
Bug
-
Resolution: Out of scope
-
P3: Somewhat important
-
4.5.0
-
None
Description
If the QGraphicsScene have not received any mouse event, any mouse event is interpreted as a LeftButton mouse event. For example the items can be selected with the right button.
Here is a test case to reproduce the problem:
#include <QtTest/QtTest> #include <QtGui/qgraphicsview.h> #include <QtGui/qgraphicsscene.h> #include <QtGui/qgraphicsitem.h> class Test : public QObject{ Q_OBJECT private slots: void testRightClicDoNotSelectItem(){ QGraphicsScene scene; QGraphicsRectItem *item = scene.addRect(0, 0, 50, 50); item->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); QGraphicsView view; view.setScene(&scene); view.show(); qApp->processEvents(); QPoint rectCenter = view.mapFromScene(item->rect().center()); QTest::mouseClick(view.viewport(), Qt::RightButton, 0, rectCenter); // should not select anything QVERIFY(!item->isSelected()); view.hide(); } }; QTEST_MAIN(Test) #include "test.moc"
Update: As a workaround, you can create a reimplementation of QGraphicsItem::mousePressEvent() in a subclass of QGraphicsItem, and ignore the event if the item is selectable when any button but Qt::LeftButton is pressed.