From 6e6d42a3b3e3769f5aa9542f836ae901bb534b8d Mon Sep 17 00:00:00 2001 From: Wladimir Leuschner Date: Tue, 10 Sep 2024 12:55:52 +0200 Subject: [PATCH] QWindows11Style: Respect background color for flat QPushButtons Fixes: QTBUG-128781 Pick-to: 6.7 Change-Id: I634d42566ea6249b125da537ac7e60fbd8475635 Reviewed-by: Christian Ehrlicher (cherry picked from commit 0b1275f630b5d03f314bc02879301df95b3f1940) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/styles/modernwindows/qwindows11style.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/plugins/styles/modernwindows/qwindows11style.cpp b/src/plugins/styles/modernwindows/qwindows11style.cpp index ac3fbbba8ee..050ac00112a 100644 --- a/src/plugins/styles/modernwindows/qwindows11style.cpp +++ b/src/plugins/styles/modernwindows/qwindows11style.cpp @@ -1433,6 +1433,8 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op if (const QStyleOptionButton *btn = qstyleoption_cast(option)) { if (btn->features.testFlag(QStyleOptionButton::Flat)) { painter->setPen(Qt::NoPen); + painter->setBrush(btn->palette.button()); + painter->drawRoundedRect(rect, secondLevelRoundingRadius, secondLevelRoundingRadius); if (flags & (State_Sunken | State_On)) { painter->setBrush(WINUI3Colors[colorSchemeIndex][subtlePressedColor]); } @@ -2154,6 +2156,10 @@ void QWindows11Style::polish(QWidget* widget) } else if (widget->inherits("QAbstractButton") || widget->inherits("QToolButton")) { widget->setAutoFillBackground(false); auto pal = widget->palette(); + if (QPushButton *btn = qobject_cast(widget)) { + if (btn->isFlat() && !pal.isBrushSet(QPalette::Active, QPalette::Button)) + pal.setColor(QPalette::Active, QPalette::Button, pal.window().color()); + } if (colorSchemeIndex == 0) { pal.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(0x00,0x00,0x00,0x5C)); pal.setColor(QPalette::Disabled, QPalette::Button, QColor(0xF9,0xF9,0xF9,0x4D));