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

Mouse events in scene not attributed to right scene item.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P2: Important P2: Important
    • 4.8.1
    • 4.7.1
    • Widgets: GraphicsView
    • None
    • Seen in Windows, Mac and Linux

      When the scaling is set to very small values, ie. 0.001, mouse events are not properly attributed to scene items in qt versions 4.7.1 and up. Things work fine in version 4.7.0. This is because of a change to the QGraphicsScenePrivate::itemsAtPosition method in qgraphicsscene.cpp in this commit: http://qt.gitorious.org/qt/qt/commit/7c0d15a22266a425c9e9ac0120d6774e120fe01e.

      I believe the problem is because the line

      const QRectF pointRect(scenePos, QSizeF(1, 1));

      sets up a very small rectangle, probably intended to be 1 x 1 pixel in size, but for small scale values, this rectangle can get rather large. The rectangle size must be scaled. I believe the following code would work, but I am not in a position to test it right now:

      QList<QGraphicsItem *> QGraphicsScenePrivate::itemsAtPosition(const QPoint &/*screenPos*/,
                                                                    const QPointF &scenePos,
                                                                    QWidget *widget) const
      {
          Q_Q(const QGraphicsScene);
          QGraphicsView *view = widget ? qobject_cast<QGraphicsView *>(widget->parentWidget()) : 0;
          if (!view)
              return q->items(scenePos, Qt::IntersectsItemShape, Qt::DescendingOrder, QTransform());
      
          if (!view->isTransformed())
              return q->items(QRectF(scenePos, QSizeF(1, 1)), Qt::IntersectsItemShape, Qt::DescendingOrder);
      
          const QTransform viewTransform = view->viewportTransform();
          return q->items(QRectF(scenePos, QSizeF(viewTransform.m11(), viewTransform.m22())), Qt::IntersectsItemShape,
                          Qt::DescendingOrder, viewTransform);
      }
      

      I have included a file that demonstrates the problem. Everything works fine when compiled with qt 4.7.0 but when compiled in qt 4.7.1 or later, the cursor and tool tips for each scene item show up outside the item's boundaries.

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

            w00t Robin Burchell
            imoir Ian Moir
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes