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
Change-Id: I798499c1484ed66662fa3ce7f3d1aeccd3f40ad7
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
(cherry picked from commit 1347ca99a30364ca9973448111a9bf40173fd81e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Wladimir Leuschner 2024-10-16 15:19:02 +02:00 committed by Qt Cherry-pick Bot
parent a8eaa0c5ac
commit 0cb772c6c3

View File

@ -1354,10 +1354,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