QHeaderView::ResizeToContents slow hide fix
authorThorbjørn Lund Martsum <tmartsum@gmail.com>
Sun, 11 Dec 2011 19:28:01 +0000 (20:28 +0100)
committerQt by Nokia <qt-info@nokia.com>
Wed, 14 Dec 2011 17:18:59 +0000 (18:18 +0100)
I have been a bit confused about what QHeaderView::ResizeToContents
does good. It only sizes depending of the visible part.

However in hide it goes crazy and checks calculates size hints
for every row. At first I considered to solve it in QTableView.
It could be made to calculate the maximum height of the maximum
screen - however I decided not to touch it since I was not
certain that it wouldn't have any unexpected side effects.

Therefore I instead made this patch which is more simple and seems
to be safer. The logic is that when a QHeaderView is hidden we actually
only want to recalculate sizes if the headerview has a visible parent.

Task-number: QTBUG-14234

Change-Id: I186ab6afa95aed43022f2bb7c36e3fd008355d9b
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
src/widgets/itemviews/qheaderview.cpp

index 36784f6..8ecbdeb 100644 (file)
@@ -2405,7 +2405,13 @@ bool QHeaderView::viewportEvent(QEvent *e)
         }
         return true; }
 #endif // QT_NO_STATUSTIP
-    case QEvent::Hide:
+    case QEvent::Hide: {
+        d->invalidateCachedSizeHint();
+        QAbstractScrollArea *parent = qobject_cast<QAbstractScrollArea *>(parentWidget());
+        if (parent && parent->isVisible()) // Only resize if we have a visible parent
+            resizeSections();
+        emit geometriesChanged();
+        break;}
     case QEvent::Show:
     case QEvent::FontChange:
     case QEvent::StyleChange: