Skip to content

Commit

Permalink
fix: 调整菜单样式
Browse files Browse the repository at this point in the history
为解决触摸屏上右键菜单的误触问题,需要菜单内容与边界有间隔.
为了美观,在有间隔后需要为其绘制圆角

Log: 调整菜单样式
Task: https://pms.uniontech.com/task-view-362001.html
Influence: 右键菜单(窗口右键菜单除外)
  • Loading branch information
Whale107 committed Sep 6, 2024
1 parent 10f54cf commit cbb2907
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions styleplugins/chameleon/chameleonstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2808,7 +2808,18 @@ void ChameleonStyle::drawMenuItemBackground(const QStyleOption *option, QPainter
}
}

painter->fillRect(option->rect, color);
painter->setBrush(color);
painter->setPen(Qt::NoPen);
painter->setRenderHint(QPainter::Antialiasing);

const int radius = DStyle::pixelMetric(PM_FrameRadius);
constexpr int margin = 6;

if (qobject_cast<QMenu *>(option->styleObject))
painter->drawRoundedRect(option->rect, radius, radius);
else
painter->drawRoundedRect(option->rect.marginsRemoved(QMargins(margin, 0, margin, 0)), radius, radius);

} else {
color = option->palette.window().color();

Expand All @@ -2833,8 +2844,6 @@ void ChameleonStyle::drawMenuItemBackground(const QStyleOption *option, QPainter
color = c;
}

painter->fillRect(option->rect, color);

if (type == QStyleOptionMenuItem::Separator) {
QColor colorSeparator;
DGuiApplicationHelper *guiAppHelp = DGuiApplicationHelper::instance();
Expand Down Expand Up @@ -4196,7 +4205,7 @@ int ChameleonStyle::pixelMetric(QStyle::PixelMetric m, const QStyleOption *opt,
case PM_MenuVMargin:
return 8;
case PM_MenuHMargin:
return 0;
return 8;
default:
break;
}
Expand Down

0 comments on commit cbb2907

Please sign in to comment.