Details
-
Bug
-
Resolution: Duplicate
-
P2: Important
-
None
-
4.7.1, 4.7.2
-
None
-
Tested only on WinXP, MSVC 2008, but seems as a global issue.
Description
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
Attachments
Issue Links
- relates to
-
QTBUG-19333 In a QGraphicsView hoverLeaveEvent and hoverEnterEvent are called outside an item (QGraphicsRectItem). The hover events get generated at points to the left or above the item.
- Closed