From f90472009c928b3f599c182dfbab91390fdafdd9 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Fri, 8 Jan 2010 12:03:48 +0100 Subject: Fixes: Setting any style sheet breaks checkbox positioning Task: QTBUG-7198 RevBy: ogoffart Details: It was impossible to override the checkbox positioning in a custom style if any style sheet was set on the application of widget. This was because the style sheet never passed control to the base style. We now fix it by checking if the style sheet has the appropriate style rules. --- src/gui/styles/qstylesheetstyle.cpp | 12 +++++++----- tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp index cf27eac..498313b 100644 --- a/src/gui/styles/qstylesheetstyle.cpp +++ b/src/gui/styles/qstylesheetstyle.cpp @@ -5611,9 +5611,6 @@ QRect QStyleSheetStyle::subElementRect(SubElement se, const QStyleOption *opt, c case SE_ItemViewItemFocusRect: if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast(opt)) { QRenderRule subRule = renderRule(w, opt, PseudoElement_ViewItem); - QStyleOptionViewItemV4 optCopy(*vopt); - optCopy.rect = subRule.contentsRect(vopt->rect); - QRect rect = ParentStyle::subElementRect(se, &optCopy, w); PseudoElement pe = PseudoElement_None; if (se == SE_ItemViewItemText || se == SE_ItemViewItemFocusRect) pe = PseudoElement_ViewItemText; @@ -5623,8 +5620,13 @@ QRect QStyleSheetStyle::subElementRect(SubElement se, const QStyleOption *opt, c pe = PseudoElement_ViewItemIndicator; else break; - QRenderRule subRule2 = renderRule(w, opt, pe); - return positionRect(w, subRule2, pe, rect, opt->direction); + if (subRule.hasGeometry() || subRule.hasBox() || !subRule.hasNativeBorder() || hasStyleRule(w, pe)) { + QRenderRule subRule2 = renderRule(w, opt, pe); + QStyleOptionViewItemV4 optCopy(*vopt); + optCopy.rect = subRule.contentsRect(vopt->rect); + QRect rect = ParentStyle::subElementRect(se, &optCopy, w); + return positionRect(w, subRule2, pe, rect, opt->direction); + } } break; #endif // QT_NO_ITEMVIEWS diff --git a/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp index 1b2f268..e0512a9 100644 --- a/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp +++ b/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp @@ -1114,7 +1114,10 @@ class ProxyStyle : public QStyle const QStyleOption* opt, const QWidget* w) const { - return style->subElementRect(se, opt, w); + Q_UNUSED(se); + Q_UNUSED(opt); + Q_UNUSED(w); + return QRect(0, 0, 3, 3); } void drawComplexControl(QStyle::ComplexControl cc, @@ -1232,7 +1235,7 @@ void tst_QStyleSheetStyle::proxyStyle() pb4->setStyleSheet(styleSheet); // We are creating our Proxy based on current style... - // In this case it would be the QStyleSheetStyle that is delete + // In this case it would be the QStyleSheetStyle that is deleted // later on. We need to get access to the "real" QStyle to be able to // draw correctly. ProxyStyle* newProxy = new ProxyStyle(qApp->style()); @@ -1248,6 +1251,13 @@ void tst_QStyleSheetStyle::proxyStyle() w->show(); QTest::qWait(100); + + // Test for QTBUG-7198 - style sheet overrides custom element size + QStyleOptionViewItemV4 opt; + opt.initFrom(w); + opt.features |= QStyleOptionViewItemV2::HasCheckIndicator; + QVERIFY(pb5->style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, + &opt, pb5).width() == 3); delete w; delete proxy; delete newProxy; -- cgit v0.12