Fix QTreeView header re-ordering bug on Mac OS.
authorChris Meyer <cmeyer1969@gmail.com>
Thu, 7 Jun 2012 14:42:43 +0000 (16:42 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 12 Jun 2012 09:16:49 +0000 (11:16 +0200)
This is a cherry-pick of 0ba850c7a2dbccb8dd6aa1664679bda6cce95065

When the mouse button is released at the end of a drag, Cocoa
may simulate an extra mouse moved event. However, the state of
the buttons when this event is generated is already 'no button'.
This leads to some failsafe code canceling out of the drag state
and when the actual mouse release event is finally processed, the
header drag state has already been exited and the header drag
fails.

This patch disables the failsafe code on Cocoa and makes header
dragging work when the mouse goes outside the bounds of the header
view.

Task-number: QTBUG-14179
Change-Id: Ia9fd1ac79f9e7b4b90d3e160298c53d65fb171d3
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
src/widgets/itemviews/qheaderview.cpp

index 2269bde..01cfc40 100644 (file)
@@ -2283,8 +2283,15 @@ void QHeaderView::mouseMoveEvent(QMouseEvent *e)
     if (pos < 0)
         return;
     if (e->buttons() == Qt::NoButton) {
+#if !defined(Q_WS_MAC)
+        // Under Cocoa, when the mouse button is released, may include an extra
+        // simulated mouse moved event. The state of the buttons when this event
+        // is generated is already "no button" and the code below gets executed
+        // just before the mouseReleaseEvent and resets the state. This prevents
+        // column dragging from working. So this code is disabled under Cocoa.
         d->state = QHeaderViewPrivate::NoState;
         d->pressed = -1;
+#endif
     }
     switch (d->state) {
         case QHeaderViewPrivate::ResizeSection: {