summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2019-10-11 10:49:38 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2019-10-14 10:17:07 +0200
commitffac8995769f27fe0d68d5e0cd75716afd3d1167 (patch)
tree11adaad9e6595c10ed7879254b9c80192d86f313 /tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
parent139246faa3322e933b5b66ebfc616bfe05a6ace6 (diff)
Fix the size calculation of QHeaderView when stylesheet is used
When calculating the header section size based on its contents when a stylesheet is used, the size hints from the stylesheet are used. In case if the stylesheet specifies only one of the sizes, the other is set to -1. Because of this the actual content size is ignored. The solution is to calculate the size based on the application style, in case if it's not specified in the stylesheet. Fixes: QTBUG-75615 Change-Id: I3453fa623d75b6b32832edf753de6e3e4e7f5a22 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Diffstat (limited to 'tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp')
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index df02815eb2..0b120985ee 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -216,6 +216,7 @@ private slots:
void QTBUG14242_hideSectionAutoSize();
void QTBUG50171_visualRegionForSwappedItems();
void QTBUG53221_assertShiftHiddenRow();
+ void QTBUG75615_sizeHintWithStylesheet();
void ensureNoIndexAtLength();
void offsetConsistent();
@@ -2606,6 +2607,26 @@ void tst_QHeaderView::QTBUG53221_assertShiftHiddenRow()
QCOMPARE(tableView.verticalHeader()->isSectionHidden(2), true);
}
+void tst_QHeaderView::QTBUG75615_sizeHintWithStylesheet()
+{
+ QTableView tableView;
+ QStandardItemModel model(1, 1);
+ tableView.setModel(&model);
+ tableView.show();
+
+ const auto headerView = tableView.horizontalHeader();
+ const auto oldSizeHint = headerView->sizeHint();
+ QVERIFY(oldSizeHint.isValid());
+
+ tableView.setStyleSheet("QTableView QHeaderView::section { height: 100px;}");
+ QCOMPARE(headerView->sizeHint().width(), oldSizeHint.width());
+ QCOMPARE(headerView->sizeHint().height(), 100);
+
+ tableView.setStyleSheet("QTableView QHeaderView::section { width: 100px;}");
+ QCOMPARE(headerView->sizeHint().height(), oldSizeHint.height());
+ QCOMPARE(headerView->sizeHint().width(), 100);
+}
+
void protected_QHeaderView::testVisualRegionForSelection()
{
QRegion r = visualRegionForSelection(QItemSelection(model()->index(1, 0), model()->index(1, 2)));