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

QGraphicsScenePrivate::itemsAtPosition creates 1x1 selection rectangle in scene coord instead of screen coord

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2: Important P2: Important
    • None
    • 4.7.1, 4.7.2
    • Widgets: GraphicsView
    • None
    • Tested only on WinXP, MSVC 2008, but seems as a global issue.

      Click selection in QGraphicsScene selects items, that are not right under mouse pointer but even a bit down or bit right.
      In 4.7.0 is everything OK.
      The bug is due to change of coordinate systems in QGraphicsScenePrivate::itemsAtPosition - function uses scene coord instead of screen coord. Documentation says that screen coord should be used.
      Parameter screenPos, that is commend out, should be used with transformations instead of direct use of scenePos ...

      Suggested fast fix (could influence other functionality):
      <code>
      /*!
      Returns all items for the screen position in \a event.
      */
      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());

      //const QRectF pointRect(scenePos, QSizeF(1, 1));//BUG - ON 20100307 - Scene coord QSizeF(1,1) is big area!!
      const QRectF pointRect = view->mapToScene(QRect(view->mapFromScene(scenePos), QSize(1, 1))).boundingRect();//Patch ON 20100307 - use screen rect of 1x1 pixel

      if (!view->isTransformed())
      return q->items(pointRect, Qt::IntersectsItemShape, Qt::DescendingOrder);

      const QTransform viewTransform = view->viewportTransform();
      return q->items(pointRect, Qt::IntersectsItemShape,
      Qt::DescendingOrder, viewTransform);
      }
      </code>

      Simple test code attached - click GenerateScene try to select/deselect objects and see debug output

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

            andysh Andy Shaw
            novako Ondrej Novak
            Votes:
            7 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes