From cbb2907595329062b2c66bd5ea9ecd7d290ea15d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A6=83=E6=9C=AC=E5=AD=A6?= Date: Fri, 6 Sep 2024 14:54:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为解决触摸屏上右键菜单的误触问题,需要菜单内容与边界有间隔. 为了美观,在有间隔后需要为其绘制圆角 Log: 调整菜单样式 Task: https://pms.uniontech.com/task-view-362001.html Influence: 右键菜单(窗口右键菜单除外) --- styleplugins/chameleon/chameleonstyle.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/styleplugins/chameleon/chameleonstyle.cpp b/styleplugins/chameleon/chameleonstyle.cpp index 52234f4..c2cff5e 100644 --- a/styleplugins/chameleon/chameleonstyle.cpp +++ b/styleplugins/chameleon/chameleonstyle.cpp @@ -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(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(); @@ -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(); @@ -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; }