summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp8
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp21
2 files changed, 29 insertions, 0 deletions
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index 88c6c288e8..3f57992311 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -5035,6 +5035,14 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op
QRenderRule subRule = renderRule(w, opt, PseudoElement_HeaderViewSection);
if (subRule.hasGeometry() || subRule.hasBox() || !subRule.hasNativeBorder() || subRule.hasFont) {
sz = subRule.adjustSize(csz);
+ if (!sz.isValid()) {
+ // Try to set the missing values based on the base style.
+ const auto baseSize = baseStyle()->sizeFromContents(ct, opt, sz, w);
+ if (sz.width() < 0)
+ sz.setWidth(baseSize.width());
+ if (sz.height() < 0)
+ sz.setHeight(baseSize.height());
+ }
if (!subRule.hasGeometry()) {
QSize nativeContentsSize;
bool nullIcon = hdr->icon.isNull();
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)));