Don't set the mouse cursor for items that are disabled

As with widgets, items that are disabled should not receive any input
events.

Similar to QGraphicsScene, which ignores disabled items when handling
mouse presses, the view should also ignore them when handling mouse
moves to update the cursor.

Since QGraphicsView only adjusts the cursors on mouse moves, reenabling
an item that is currently under the mouse will not change the cursor.
This is consistent with other changes of item attributes that would
position the item under the mouse (such as moving it). The overhead of
hit-testing items for every such attribute change would be too large,
and applications can generate a mouse move event if they really need
to adjust the cursor in all situations.

[ChangeLog][QtWidgets][QGraphicsView] Ignore disabled items when setting
the mouse cursor.

Fixes: QTBUG-76765
Change-Id: Ifcd31fc0581e8421e58eeb436a55b031909eed7e
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Volker Hilsheimer 2019-07-05 17:24:22 +02:00
parent 307403f8b4
commit d8688d4484
2 changed files with 11 additions and 2 deletions

View File

@ -691,7 +691,7 @@ void QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent *event)
}
// Find the topmost item under the mouse with a cursor.
foreach (QGraphicsItem *item, scene->d_func()->cachedItemsUnderMouse) {
if (item->hasCursor()) {
if (item->isEnabled() && item->hasCursor()) {
_q_setViewportCursor(item->cursor());
return;
}
@ -808,7 +808,7 @@ void QGraphicsViewPrivate::_q_unsetViewportCursor()
Q_Q(QGraphicsView);
const auto items = q->items(lastMouseEvent.pos());
for (QGraphicsItem *item : items) {
if (item->hasCursor()) {
if (item->isEnabled() && item->hasCursor()) {
_q_setViewportCursor(item->cursor());
return;
}

View File

@ -4219,6 +4219,15 @@ void tst_QGraphicsItem::cursor()
}
QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape);
item1->setEnabled(false);
{
QTest::mouseMove(view.viewport(), item1Center);
QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, 0, 0);
QApplication::sendEvent(view.viewport(), &event);
}
QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape);
}
#endif
/*