Fix mouse cursor behavior for QMainWindow splitters

The cursor handling has changed in Qt5 somewhat, which made old cursor
logic for splitters invalid, causing the splitter resize cursor to
persist after hovering over splitter, as well as cursor flicker
during splitter drag.

Since the cursor is changed always in dispatchEnterLeave, CursorChange
event can now come for QMainWindow when cursor hasn't actually changed,
so we now check if the cursor is still our adjusted cursor before
updating the old stored cursor. We also ensure that our adjusted cursor
stays visible if cursor is in fact changed - the changed cursor will
be shown when we no longer need adjusted cursor.

Additionally, we skip cursor adjustments while we are dragging the
splitter to avoid cursor flicker, which is caused by splitter actually
moving asynchronously after the mouse event is handled.

Task-number: QTBUG-27970
Change-Id: Id9f6a0e9653563e09b883f21396de056a88f78a7
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
This commit is contained in:
Miikka Heikkinen 2012-11-13 14:10:32 +02:00 committed by The Qt Project
parent aa309b9677
commit 90de0c4178

View File

@ -100,6 +100,7 @@ public:
QCursor separatorCursor(const QList<int> &path) const;
void adjustCursor(const QPoint &pos);
QCursor oldCursor;
QCursor adjustedCursor;
uint hasOldCursor : 1;
uint cursorAdjusted : 1;
#endif
@ -1300,7 +1301,7 @@ void QMainWindowPrivate::adjustCursor(const QPoint &pos)
else
q->unsetCursor();
}
} else {
} else if (layout->movingSeparator.isEmpty()) { // Don't change cursor when moving separator
QList<int> pathToSeparator
= layout->layoutState.dockAreaLayout.findSeparator(pos);
@ -1324,9 +1325,8 @@ void QMainWindowPrivate::adjustCursor(const QPoint &pos)
oldCursor = q->cursor();
hasOldCursor = q->testAttribute(Qt::WA_SetCursor);
}
QCursor cursor = separatorCursor(hoverSeparator);
cursorAdjusted = false; //to not reset the oldCursor in event(CursorChange)
q->setCursor(cursor);
adjustedCursor = separatorCursor(hoverSeparator);
q->setCursor(adjustedCursor);
cursorAdjusted = true;
}
}
@ -1452,9 +1452,15 @@ bool QMainWindow::event(QEvent *event)
#endif // Q_WS_MAC
#if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR)
case QEvent::CursorChange:
if (d->cursorAdjusted) {
// CursorChange events are triggered as mouse moves to new widgets even
// if the cursor doesn't actually change, so do not change oldCursor if
// the "changed" cursor has same shape as adjusted cursor.
if (d->cursorAdjusted && d->adjustedCursor.shape() != cursor().shape()) {
d->oldCursor = cursor();
d->hasOldCursor = testAttribute(Qt::WA_SetCursor);
// Ensure our adjusted cursor stays visible
setCursor(d->adjustedCursor);
}
break;
#endif