summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2017-11-12 13:33:25 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2017-11-17 20:28:34 +0000
commitba2f3a156ebc9ce3e6b6e59e231a5c2847163671 (patch)
treea30f85026a2046dd16f7f346da40ee5a5732a65a /tests
parent5c0a9fc532d70ae784cca3e16b5fe59862902815 (diff)
QTreeView: recalculate row heights in hide/showColumn()
When calling QTreeView::hideColumn() the row heights are not recalculated. This can lead to rows which are unnecessarily high due to hidden columns may contain large (e.g. multiline) content. The same applies to showColumn() - there the row might be to small. Hiding columns directly via QTreeView::header()->hideSection() is not covered by this patch since QHeaderView has no way to inform about newly shown/hidden sections. Task-number: QTBUG-8376 Change-Id: I20b1198e56e403ab8cf649af76e5e2280821dd68 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
index 6ee0e50cce..3260d7c968 100644
--- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
@@ -193,6 +193,7 @@ private slots:
void taskQTBUG_37813_crash();
void taskQTBUG_45697_crash();
void taskQTBUG_7232_AllowUserToControlSingleStep();
+ void taskQTBUG_8376();
void testInitialFocus();
};
@@ -4399,5 +4400,51 @@ void tst_QTreeView::taskQTBUG_7232_AllowUserToControlSingleStep()
QCOMPARE(hStep1, t.horizontalScrollBar()->singleStep());
}
+static void fillModeltaskQTBUG_8376(QAbstractItemModel &model)
+{
+ model.insertRow(0);
+ model.insertColumn(0);
+ model.insertColumn(1);
+ QModelIndex index = model.index(0, 0);
+ model.setData(index, "Level0");
+ {
+ model.insertRow(0, index);
+ model.insertRow(1, index);
+ model.insertColumn(0, index);
+ model.insertColumn(1, index);
+
+ QModelIndex idx;
+ idx = model.index(0, 0, index);
+ model.setData(idx, "Level1");
+
+ idx = model.index(0, 1, index);
+ model.setData(idx, "very\nvery\nhigh\ncell");
+ }
+}
+
+void tst_QTreeView::taskQTBUG_8376()
+{
+ QTreeView tv;
+ QStandardItemModel model;
+ fillModeltaskQTBUG_8376(model);
+ tv.setModel(&model);
+ tv.expandAll(); // init layout
+
+ QModelIndex idxLvl0 = model.index(0, 0);
+ QModelIndex idxLvl1 = model.index(0, 1, idxLvl0);
+ const int rowHeightLvl0 = tv.rowHeight(idxLvl0);
+ const int rowHeightLvl1Visible = tv.rowHeight(idxLvl1);
+ QVERIFY(rowHeightLvl0 < rowHeightLvl1Visible);
+
+ tv.hideColumn(1);
+ const int rowHeightLvl1Hidden = tv.rowHeight(idxLvl1);
+ QCOMPARE(rowHeightLvl0, rowHeightLvl1Hidden);
+
+ tv.showColumn(1);
+ const int rowHeightLvl1Visible2 = tv.rowHeight(idxLvl1);
+ QCOMPARE(rowHeightLvl1Visible, rowHeightLvl1Visible2);
+}
+
+
QTEST_MAIN(tst_QTreeView)
#include "tst_qtreeview.moc"