From 1347ca99a30364ca9973448111a9bf40173fd81e Mon Sep 17 00:00:00 2001 From: Wladimir Leuschner Date: Wed, 16 Oct 2024 15:19:02 +0200 Subject: [PATCH] QWindows11Style: Add menu indicator to QPushButton In case a menu was associated with a QPushButton, draw a triangle indicator that shows, that a menu will open up. Fixes: QTBUG-130122 Pick-to: 6.8 Change-Id: I798499c1484ed66662fa3ce7f3d1aeccd3f40ad7 Reviewed-by: Oliver Wolff --- .../styles/modernwindows/qwindows11style.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/plugins/styles/modernwindows/qwindows11style.cpp b/src/plugins/styles/modernwindows/qwindows11style.cpp index 97f245d8b7f..20cf24b996f 100644 --- a/src/plugins/styles/modernwindows/qwindows11style.cpp +++ b/src/plugins/styles/modernwindows/qwindows11style.cpp @@ -1373,10 +1373,24 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op if (btn->features & QStyleOptionButton::HasMenu) { int indicatorSize = proxy()->pixelMetric(PM_MenuButtonIndicator, btn, widget); - if (btn->direction == Qt::LeftToRight) + QLineF menuSplitter; + QRectF indicatorRect; + painter->setFont(assetFont); + + if (btn->direction == Qt::LeftToRight) { + indicatorRect = QRect(textRect.x() + textRect.width() - indicatorSize - 4, textRect.y(),2 * 4 + indicatorSize, textRect.height()); + indicatorRect.adjust(0.5,-0.5,0.5,0.5); + menuSplitter = QLineF(indicatorRect.topLeft(),indicatorRect.bottomLeft()); textRect = textRect.adjusted(0, 0, -indicatorSize, 0); - else + } else { + indicatorRect = QRect(textRect.x(), textRect.y(), textRect.x() + indicatorSize + 4, textRect.height()); + indicatorRect.adjust(-0.5,-0.5,-0.5,0.5); + menuSplitter = QLineF(indicatorRect.topRight(),indicatorRect.bottomRight()); textRect = textRect.adjusted(indicatorSize, 0, 0, 0); + } + painter->drawText(indicatorRect,"\uE70D",Qt::AlignVCenter|Qt::AlignHCenter); + painter->setPen(QPen(WINUI3Colors[colorSchemeIndex][controlStrokePrimary])); + painter->drawLine(menuSplitter); } if (!btn->icon.isNull()) { //Center both icon and text