QWindows11Style: Update font size in menubar items and spacing between items

Reduce the spacing between menu bar items and change
font size to 10pt.

Fixes: QTBUG-120639
Change-Id: Ic16e74f4a2426be6d6ef40904919d92785d96ce5
Reviewed-by: Robert Löhning <robert.loehning@qt.io>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
(cherry picked from commit f75e554c6af7ea00bb5e6aa62a2af26350b67d98)
This commit is contained in:
Wladimir Leuschner 2024-01-22 15:37:19 +01:00 committed by Jani Heikkinen
parent 1e96139cf2
commit d11d503850

View File

@ -1365,21 +1365,27 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op
break; break;
case CE_MenuBarItem: case CE_MenuBarItem:
if (const auto *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) { if (const auto *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
constexpr int hPadding = 11;
constexpr int topPadding = 4;
constexpr int bottomPadding = 6;
bool active = mbi->state & State_Selected; bool active = mbi->state & State_Selected;
bool hasFocus = mbi->state & State_HasFocus; bool hasFocus = mbi->state & State_HasFocus;
bool down = mbi->state & State_Sunken; bool down = mbi->state & State_Sunken;
bool enabled = mbi->state & State_Enabled; bool enabled = mbi->state & State_Enabled;
QStyleOptionMenuItem newMbi = *mbi; QStyleOptionMenuItem newMbi = *mbi;
newMbi.font.setPointSize(10);
if (enabled && (active || hasFocus)) { if (enabled && (active || hasFocus)) {
if (active && down) if (active && down)
painter->setBrushOrigin(painter->brushOrigin() + QPoint(1, 1)); painter->setBrushOrigin(painter->brushOrigin() + QPoint(1, 1));
if (active && hasFocus) { if (active && hasFocus) {
painter->setBrush(WINUI3Colors[colorSchemeIndex][subtleHighlightColor]); painter->setBrush(WINUI3Colors[colorSchemeIndex][subtleHighlightColor]);
painter->setPen(Qt::NoPen); painter->setPen(Qt::NoPen);
QRect rect = mbi->rect.marginsRemoved(QMargins(2,2,2,2)); QRect rect = mbi->rect.marginsRemoved(QMargins(5,0,5,0));
painter->drawRoundedRect(rect,secondLevelRoundingRadius,secondLevelRoundingRadius,Qt::AbsoluteSize); painter->drawRoundedRect(rect,secondLevelRoundingRadius,secondLevelRoundingRadius,Qt::AbsoluteSize);
} }
} }
newMbi.rect.adjust(hPadding,topPadding,-hPadding,-bottomPadding);
painter->setFont(newMbi.font);
QCommonStyle::drawControl(element, &newMbi, painter, widget); QCommonStyle::drawControl(element, &newMbi, painter, widget);
} }
break; break;
@ -1880,8 +1886,13 @@ QSize QWindows11Style::sizeFromContents(ContentsType type, const QStyleOption *o
#if QT_CONFIG(menubar) #if QT_CONFIG(menubar)
case CT_MenuBarItem: case CT_MenuBarItem:
if (!contentSize.isEmpty()) if (!contentSize.isEmpty()) {
contentSize += QSize(QWindowsVistaStylePrivate::windowsItemHMargin * 5 + 1 + 16, 5 + 16); constexpr int hMargin = 2 * 6;
constexpr int hPadding = 2 * 11;
constexpr int itemHeight = 32;
contentSize.setWidth(contentSize.width() + hMargin + hPadding);
contentSize.setHeight(itemHeight);
}
break; break;
#endif #endif