Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.2.4, 6.3.1
-
None
Description
QMenu doesn't calculate the correct width for items with icon if the font size is larger than default.
I came across this bug when trying to populate menu with items with icons 48x48 in size and using DejaVu font 21px in size. I've customized the style using both a stylesheet (setting up font size, background and borders) and QStyle derived class to override pixelMetric for PM_SmallIconSize.
In the end the problem still exists even without changes to icon size and with minimal changes in stylesheet. I tracked it down to the void QMenuPrivate::updateActionRects(const QRect &screen) const function in QMenu.cpp. The value of maxIconWidth variable (line: 387) is not being passed anywhere. I think it should be saved to QStyleOptionMenuItem opt; (line: 423, not to be confused withQStyleOption opt; defined at line 372), such that when it's passed to sizeFromContents it will be properly added to the final width.
I've compiled an image showing different results for different font sizes, with and without icons.
Steps to reproduce:
- define QMenu and populate it with actions with icons
- set stylesheet with "QMenu::item { font-size: 21px; }"
- create a window, add QToolButton and add menu to it
- open the menu and enjoy the text being clipped
This happens as soon as at least one item in menu has an icon