Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-3582

QGraphicsItem::mouseReleaseEvent() do not behave correctly for the first event

    XMLWordPrintable

Details

    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.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            poulain Benjamin Poulain (closed Nokia identity) (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes