Windows11Style: fix painting checked QToolButton
A checked QToolButton should be drawn similar to a checked QPushButton. As a drive-by avoid calculating the paint rect twice and make the code a little bit more readable. Fixes: QTBUG-129439 Fixes: QTBUG-129700 Fixes: QTBUG-130822 Change-Id: I573132e804f26b9fa41112267a9f685680cf0864 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit b3c0b08eb040bbd76b81a7c6172e3846e8ec0000) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>bb10
parent
1be6e99b55
commit
53a5df8cf0
|
|
@ -885,29 +885,30 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption
|
|||
break;
|
||||
case PE_PanelButtonTool:
|
||||
case PE_PanelButtonBevel:{
|
||||
QRectF rect = option->rect.marginsRemoved(QMargins(2,2,2,2));
|
||||
rect.adjust(-0.5,-0.5,0.5,0.5);
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
if (element == PE_PanelButtonTool
|
||||
&& ((!(state & QStyle::State_MouseOver) && !(state & QStyle::State_Raised))
|
||||
|| !(state & QStyle::State_Enabled)))
|
||||
const bool isEnabled = state & QStyle::State_Enabled;
|
||||
const bool isMouseOver = state & QStyle::State_MouseOver;
|
||||
const bool isRaised = state & QStyle::State_Raised;
|
||||
const QRectF rect = option->rect.marginsRemoved(QMargins(2,2,2,2));
|
||||
if (element == PE_PanelButtonTool && ((!isMouseOver && !isRaised) || !isEnabled))
|
||||
painter->setPen(Qt::NoPen);
|
||||
else
|
||||
painter->setPen(QPen(WINUI3Colors[colorSchemeIndex][controlStrokePrimary]));
|
||||
painter->drawRoundedRect(rect, secondLevelRoundingRadius, secondLevelRoundingRadius);
|
||||
painter->setBrush(buttonFillBrush(option));
|
||||
painter->drawRoundedRect(rect.marginsAdded(QMargins(0.5, 0.5, 0.5, 0.5)),
|
||||
secondLevelRoundingRadius, secondLevelRoundingRadius);
|
||||
|
||||
rect = option->rect.marginsRemoved(QMargins(2,2,2,2));
|
||||
painter->setPen(Qt::NoPen);
|
||||
if (!(state & (State_Raised)))
|
||||
if (!isRaised)
|
||||
painter->setBrush(WINUI3Colors[colorSchemeIndex][controlFillTertiary]);
|
||||
else if (state & State_MouseOver)
|
||||
else if (isMouseOver)
|
||||
painter->setBrush(WINUI3Colors[colorSchemeIndex][controlFillSecondary]);
|
||||
else
|
||||
painter->setBrush(option->palette.button());
|
||||
painter->drawRoundedRect(rect, secondLevelRoundingRadius, secondLevelRoundingRadius);
|
||||
painter->setPen(QPen(WINUI3Colors[colorSchemeIndex][controlStrokeSecondary]));
|
||||
if (state & State_Raised)
|
||||
if (isRaised) {
|
||||
painter->setPen(QPen(WINUI3Colors[colorSchemeIndex][controlStrokeSecondary]));
|
||||
painter->drawLine(rect.bottomLeft() + QPoint(2,1), rect.bottomRight() + QPoint(-2,1));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PE_FrameDefaultButton:
|
||||
|
|
@ -2294,6 +2295,8 @@ QBrush QWindows11Style::buttonFillBrush(const QStyleOption *option)
|
|||
{
|
||||
const bool isOn = (option->state & QStyle::State_On || option->state & QStyle::State_NoChange);
|
||||
QBrush brush = isOn ? option->palette.accent() : option->palette.window();
|
||||
if (!isOn && option->state & QStyle::State_AutoRaise)
|
||||
return Qt::NoBrush;
|
||||
if (option->state & QStyle::State_MouseOver)
|
||||
brush.setColor(isOn ? brush.color().lighter(107) : brush.color().darker(107));
|
||||
return brush;
|
||||
|
|
|
|||
Loading…
Reference in New Issue