QHeaderView: add test for not overwriting resized sections
If we change, reset or update the default section size, e.g. in response to style changes or programmatically, then we don't want to override explicitly specified column widths in e.g. a tree view. Add a test that verifies that we don't overwrite. Task-number: QTBUG-116013 Task-number: QTBUG-122109 Task-number: QTBUG-123154 Change-Id: I3d9a6ac685da39a59436b91f56e86b0f705e645c Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit 3ca0288aa927108de4c57119d9767998021a6089) Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
9f79ffe8f0
commit
800d7138a3
@ -229,6 +229,7 @@ private slots:
|
||||
void testModelMovingColumns();
|
||||
void testModelMovingRows();
|
||||
|
||||
void setDefaultSectionSizeRespectsColumnWidth();
|
||||
protected:
|
||||
void setupTestData(bool use_reset_model = false);
|
||||
void additionalInit();
|
||||
@ -3685,5 +3686,32 @@ void tst_QHeaderView::testModelMovingRows()
|
||||
QVERIFY(!hv.isSectionHidden(3));
|
||||
}
|
||||
|
||||
void tst_QHeaderView::setDefaultSectionSizeRespectsColumnWidth()
|
||||
{
|
||||
QTreeWidget tree;
|
||||
tree.setHeaderItem(new QTreeWidgetItem({"Col 0", "Col 1", "Col 2"}));
|
||||
tree.header()->setStretchLastSection(false);
|
||||
|
||||
int columnWidths[3] = {};
|
||||
for (int c = tree.columnCount() - 1; c >= 0; --c) {
|
||||
columnWidths[c] = tree.columnWidth(c) * 2;
|
||||
tree.setColumnWidth(c, columnWidths[c]);
|
||||
}
|
||||
tree.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&tree));
|
||||
|
||||
for (int c = 0; c < tree.columnCount(); ++c)
|
||||
QTRY_COMPARE(tree.columnWidth(c), columnWidths[c]);
|
||||
|
||||
// trigger a style change event
|
||||
tree.setStyleSheet("QTreeView { qproperty-headerHidden: true }");
|
||||
QTRY_COMPARE(tree.isHeaderHidden(), true);
|
||||
tree.setStyleSheet("QTreeView { qproperty-headerHidden: false }");
|
||||
QTRY_COMPARE(tree.isHeaderHidden(), false);
|
||||
|
||||
for (int c = 0; c < tree.columnCount(); ++c)
|
||||
QTRY_COMPARE(tree.columnWidth(c), columnWidths[c]);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QHeaderView)
|
||||
#include "tst_qheaderview.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user