diff options
-rw-r--r-- | src/gui/styles/qstylesheetstyle.cpp | 14 | ||||
-rw-r--r-- | tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp | 23 |
2 files changed, 36 insertions, 1 deletions
diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp index f22cd56..a39eeb7 100644 --- a/src/gui/styles/qstylesheetstyle.cpp +++ b/src/gui/styles/qstylesheetstyle.cpp @@ -2916,6 +2916,10 @@ void QStyleSheetStyle::polish(QWidget *w) if (ew->autoFillBackground()) { ew->setAutoFillBackground(false); autoFillDisabledWidgets->insert(w); + if (ew != w) { //eg. viewport of a scrollarea + //(in order to draw the background anyway in case we don't.) + ew->setAttribute(Qt::WA_StyledBackground, true); + } } if (!rule.hasBackground() || rule.background()->isTransparent() || rule.hasBox() || (!rule.hasNativeBorder() && !rule.border()->isOpaque())) @@ -4345,8 +4349,16 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op return; case PE_Widget: - if (!rule.hasBackground()) + if (!rule.hasBackground()) { + QWidget *container = containerWidget(w); + if (autoFillDisabledWidgets->contains(container) + && (container == w || !renderRule(container, opt).hasBackground())) { + //we do not have a background, but we disabled the autofillbackground anyway. so fill the background now. + // (this may happen if we have rules like :focus) + p->fillRect(opt->rect, opt->palette.brush(w->backgroundRole())); + } break; + } #ifndef QT_NO_SCROLLAREA if (const QAbstractScrollArea *sa = qobject_cast<const QAbstractScrollArea *>(w)) { diff --git a/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp index 7954d00..aa63753 100644 --- a/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp +++ b/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp @@ -94,6 +94,7 @@ private slots: void embeddedFonts(); void opaquePaintEvent_data(); void opaquePaintEvent(); + void task188195_baseBackground(); //at the end because it mess with the style. void widgetStyle(); @@ -1354,6 +1355,28 @@ void tst_QStyleSheetStyle::opaquePaintEvent() QCOMPARE(cl.autoFillBackground(), !styled ); } +void tst_QStyleSheetStyle::task188195_baseBackground() +{ + QTreeView tree; + tree.setStyleSheet( "QTreeView:disabled { background-color:#ab1251; }" ); + tree.show(); + QTest::qWait(20); + QImage image(tree.width(), tree.height(), QImage::Format_ARGB32); + + tree.render(&image); + QVERIFY(testForColors(image, tree.palette().base().color())); + QVERIFY(!testForColors(image, QColor(0xab, 0x12, 0x51))); + + tree.setEnabled(false); + tree.render(&image); + QVERIFY(testForColors(image, QColor(0xab, 0x12, 0x51))); + + tree.setEnabled(true); + tree.render(&image); + QVERIFY(testForColors(image, tree.palette().base().color())); + QVERIFY(!testForColors(image, QColor(0xab, 0x12, 0x51))); +} + QTEST_MAIN(tst_QStyleSheetStyle) |