Windows11Style: allow overriding of palette for QPush/ToolButton

Honor the palette set by the stylesheet when drawing a
QPush/ToolButton.

Pick-to: 6.9 6.8
Fixes: QTBUG-134497
Change-Id: I33b9cdf8d4999e1fccdae250543db541b66b3b7d
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Christian Ehrlicher 2024-12-31 11:38:43 +01:00
parent 0de9b3f126
commit b0dec15d2d

View File

@ -906,14 +906,17 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption
painter->drawRoundedRect(rect, painter->drawRoundedRect(rect,
secondLevelRoundingRadius, secondLevelRoundingRadius); secondLevelRoundingRadius, secondLevelRoundingRadius);
painter->setPen(Qt::NoPen); if (!option->palette.isBrushSet(QPalette::Current, QPalette::Button)) {
if (!isRaised) painter->setPen(Qt::NoPen);
painter->setBrush(WINUI3Colors[colorSchemeIndex][controlFillTertiary]); if (!isRaised)
else if (isMouseOver) painter->setBrush(WINUI3Colors[colorSchemeIndex][controlFillTertiary]);
painter->setBrush(WINUI3Colors[colorSchemeIndex][controlFillSecondary]); else if (isMouseOver)
else painter->setBrush(WINUI3Colors[colorSchemeIndex][controlFillSecondary]);
painter->setBrush(option->palette.button()); else
painter->drawRoundedRect(rect, secondLevelRoundingRadius, secondLevelRoundingRadius); painter->setBrush(option->palette.button());
painter->drawRoundedRect(rect, secondLevelRoundingRadius,
secondLevelRoundingRadius);
}
if (isRaised) { if (isRaised) {
const qreal sublineOffset = secondLevelRoundingRadius - 0.5; const qreal sublineOffset = secondLevelRoundingRadius - 0.5;
painter->setPen(WINUI3Colors[colorSchemeIndex][controlStrokeSecondary]); painter->setPen(WINUI3Colors[colorSchemeIndex][controlStrokeSecondary]);
@ -1465,7 +1468,9 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op
} }
painter->drawRoundedRect(rect, secondLevelRoundingRadius, secondLevelRoundingRadius); painter->drawRoundedRect(rect, secondLevelRoundingRadius, secondLevelRoundingRadius);
} else { } else {
if (flags & (State_Sunken)) if (option->palette.isBrushSet(QPalette::Current, QPalette::Button))
painter->setBrush(option->palette.button());
else if (flags & (State_Sunken))
painter->setBrush(flags & State_On ? option->palette.accent().color().lighter(120) : WINUI3Colors[colorSchemeIndex][controlFillTertiary]); painter->setBrush(flags & State_On ? option->palette.accent().color().lighter(120) : WINUI3Colors[colorSchemeIndex][controlFillTertiary]);
else if (flags & State_MouseOver) else if (flags & State_MouseOver)
painter->setBrush(flags & State_On ? option->palette.accent().color().lighter(110) : WINUI3Colors[colorSchemeIndex][controlFillSecondary]); painter->setBrush(flags & State_On ? option->palette.accent().color().lighter(110) : WINUI3Colors[colorSchemeIndex][controlFillSecondary]);
@ -2354,6 +2359,9 @@ void QWindows11Style::polish(QPalette& result)
QBrush QWindows11Style::buttonFillBrush(const QStyleOption *option) QBrush QWindows11Style::buttonFillBrush(const QStyleOption *option)
{ {
if (option->palette.isBrushSet(QPalette::Current, QPalette::Button))
return option->palette.button();
const bool isOn = (option->state & QStyle::State_On || option->state & QStyle::State_NoChange); const bool isOn = (option->state & QStyle::State_On || option->state & QStyle::State_NoChange);
QBrush brush = isOn ? option->palette.accent() : option->palette.window(); QBrush brush = isOn ? option->palette.accent() : option->palette.window();
if (!isOn && option->state & QStyle::State_AutoRaise) if (!isOn && option->state & QStyle::State_AutoRaise)