summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp6
-rw-r--r--tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp24
2 files changed, 27 insertions, 3 deletions
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index 6528615c694..583d2061ed4 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -6485,9 +6485,9 @@ void QStyleSheetStyle::updateStyleSheetFont(QWidget* w) const
font.setResolveMask(wf.resolveMask() | rule.font.resolveMask());
if ((!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))
- && isNaturalChild(w) && qobject_cast<QWidget *>(w->parent())) {
-
- font = font.resolve(static_cast<QWidget *>(w->parent())->font());
+ && isNaturalChild(w) && w->parentWidget()) {
+ const auto parentFont = w->parentWidget()->font();
+ font = rule.hasFont ? font.resolve(parentFont) : parentFont;
}
if (wf.resolveMask() == font.resolveMask() && wf == font)
diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
index a9a1817b8a0..a1bbf14bd61 100644
--- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
+++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
@@ -125,6 +125,8 @@ private slots:
void inheritWidgetPalette_data();
void inheritWidgetPalette();
+ void resetFont();
+
private:
static QColor COLOR(const QWidget &w)
{
@@ -2528,6 +2530,28 @@ void tst_QStyleSheetStyle::inheritWidgetPalette()
QCOMPARE(phColor, phColorPalette);
}
+void tst_QStyleSheetStyle::resetFont()
+{
+ QDoubleSpinBox sb;
+ sb.setStyleSheet(R"(QDoubleSpinBox[changed="true"] {font: italic;})");
+
+ auto checkFont = [&sb](bool isItalic) {
+ sb.setProperty("changed", isItalic);
+ sb.style()->polish(&sb);
+ const auto children = sb.findChildren<QWidget *>();
+ for (const auto *w : children) {
+ auto diagnostics = qScopeGuard([&] {
+ qWarning() << "Failure with" << w << "should be italic:" << isItalic;
+ });
+ QCOMPARE(w->font().italic(), isItalic);
+ diagnostics.dismiss();
+ }
+ };
+ checkFont(false);
+ checkFont(true);
+ checkFont(false);
+}
+
QTEST_MAIN(tst_QStyleSheetStyle)
#include "tst_qstylesheetstyle.moc"