From 90de0c417883aa515a694fa56b0e84c8969971fe Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 13 Nov 2012 14:10:32 +0200 Subject: Fix mouse cursor behavior for QMainWindow splitters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Samuel Rødal --- src/widgets/widgets/qmainwindow.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qmainwindow.cpp b/src/widgets/widgets/qmainwindow.cpp index 93492bab61..056e2cbacc 100644 --- a/src/widgets/widgets/qmainwindow.cpp +++ b/src/widgets/widgets/qmainwindow.cpp @@ -100,6 +100,7 @@ public: QCursor separatorCursor(const QList &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 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 -- cgit v1.2.3