Skip to content

Commit f98f1ca

Browse files
committed
fix: missing antialiased for menuItem
Add antialiased for painter. Fix MenuItem's HMargin implementation, Remove the margin of MenuItem's width instead of the margin of PM_MenuHMargin, otherwise, it caused incorrrect suMenu overlap. pms: BUG-297003
1 parent c8b538d commit f98f1ca

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

styleplugins/chameleon/chameleonstyle.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,12 +3076,14 @@ bool ChameleonStyle::drawMenuBarItem(const QStyleOptionMenuItem *option, QRect &
30763076
ChameleonMovementAnimation *ChameleonStyle::drawMenuItemBackground(const QStyleOption *option, QPainter *painter, QStyleOptionMenuItem::MenuItemType type) const
30773077
{
30783078
QBrush color;
3079+
constexpr int margin = 6; // margin of MenuItem's bounding.
3080+
const auto rect = option->rect.marginsRemoved(QMargins(margin, 0, margin, 0));
30793081
bool selected = (option->state & QStyle::State_Enabled) && option->state & QStyle::State_Selected;
30803082
if (selected && (DGuiApplicationHelper::isTabletEnvironment() ||
30813083
!DGuiApplicationHelper::isSpecialEffectsEnvironment())) {
30823084
painter->setPen(Qt::NoPen);
30833085
painter->setBrush(getColor(option, QPalette::Highlight));
3084-
painter->drawRect(option->rect);
3086+
painter->drawRect(rect);
30853087
return nullptr;
30863088
}
30873089

@@ -3117,7 +3119,7 @@ ChameleonMovementAnimation *ChameleonStyle::drawMenuItemBackground(const QStyleO
31173119
colorSeparator = QColor(255, 255, 255, 255 * 0.05);
31183120
else
31193121
colorSeparator = QColor(0, 0, 0, 255 * 0.1);
3120-
painter->fillRect(option->rect, colorSeparator);
3122+
painter->fillRect(rect, colorSeparator);
31213123
}
31223124

31233125
if (!option->styleObject)
@@ -3143,7 +3145,7 @@ ChameleonMovementAnimation *ChameleonStyle::drawMenuItemBackground(const QStyleO
31433145
}
31443146

31453147
if (selected)
3146-
animation->setTargetRect(option->rect);
3148+
animation->setTargetRect(rect);
31473149
}
31483150
const int round = 6;
31493151
if (animation && animation->isRuning()) {
@@ -3153,6 +3155,7 @@ ChameleonMovementAnimation *ChameleonStyle::drawMenuItemBackground(const QStyleO
31533155
painter->setOpacity(1.0);
31543156
painter->setBrush(color);
31553157
painter->setPen(Qt::NoPen);
3158+
painter->setRenderHint(QPainter::Antialiasing);
31563159
painter->drawRoundedRect(animation->currentRect(), round, round);
31573160
painter->setOpacity(opacity);
31583161
painter->restore();
@@ -3162,7 +3165,8 @@ ChameleonMovementAnimation *ChameleonStyle::drawMenuItemBackground(const QStyleO
31623165
painter->save();
31633166
painter->setBrush(color);
31643167
painter->setPen(Qt::NoPen);
3165-
painter->drawRoundedRect(option->rect, round, round);
3168+
painter->setRenderHint(QPainter::Antialiasing);
3169+
painter->drawRoundedRect(rect, round, round);
31663170
painter->restore();
31673171
}
31683172
}
@@ -4496,7 +4500,7 @@ int ChameleonStyle::pixelMetric(QStyle::PixelMetric m, const QStyleOption *opt,
44964500
case PM_MenuVMargin:
44974501
return 8;
44984502
case PM_MenuHMargin:
4499-
return 6;
4503+
return 0;
45004504
default:
45014505
break;
45024506
}

0 commit comments

Comments
 (0)