Summary: | Multi-line menu text for menu items displayed incorrectly | ||
---|---|---|---|
Product: | [Plasma] Breeze | Reporter: | Ilya Bizyaev <bizyaev> |
Component: | QStyle | Assignee: | Plasma Bugs List <plasma-bugs> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | materka, nate, noahadvs, uhhadd |
Priority: | NOR | ||
Version: | 5.27.9 | ||
Target Milestone: | --- | ||
Platform: | openSUSE | ||
OS: | Linux | ||
Latest Commit: | https://invent.kde.org/plasma/breeze/-/commit/a5f463e236639370ba2770b7bc0e28dbe777b0eb | Version Fixed In: | 6.0 |
Sentry Crash Report: | |||
Attachments: |
A minimal example
Screenshot of the issue Updated SNI example (Qt 6) Sample app (PyQt6) |
Description
Ilya Bizyaev
2023-11-20 21:36:39 UTC
Created attachment 163323 [details]
A minimal example
Created attachment 163324 [details]
Screenshot of the issue
Note that the QMenu in the script is not the QMenu that is actually displayed to the user, it is only used to export the intended menu items to D-Bus. In a GTK program, it would be a GTK menu object, etc. A possibly relevant merge request was started @ https://invent.kde.org/plasma/breeze/-/merge_requests/414 Created attachment 165222 [details]
Updated SNI example (Qt 6)
Created attachment 165223 [details]
Sample app (PyQt6)
Git commit a4d892f68ce77198812fccbeabfb79f97ce36688 by Ilya Bizyaev. Committed on 30/01/2024 at 11:19. Pushed by ilyabizyaev into branch 'master'. Fix display of multiline menu items Currently, multiline text in menu items is displayed incorrectly: the bounding rectangle is calculated ignoring newlines, while the newline is displayed in the resulting menu, and the text is cropped. This commit makes it so the newline is considered in the calculation as well. To do so, we get text metrics ourselves instead of delegating it to the ancient QMenu code that forces `Qt::TextSingleLine`. Note that this approach is not new: * In Breeze, the code right below for `QStyleOptionMenuItem::Separator` also gets text metrics. * In Qt, the Fusion style also requests font metrics: https://invent.kde.org/qt/qt/qtbase/-/blob/dev/src/widgets/styles/qfusionstyle.cpp#L3084-3088 Note that this commit does not imply that it is a good idea to use multiline menu item text in KDE apps from now on; it merely fixes an existing rendering defect that caused multiline actions to look wrong in StatusNotifierItems. Before:  After:  With icons:  In a very imaginary app:  M +10 -2 kstyle/breezestyle.cpp https://invent.kde.org/plasma/breeze/-/commit/a4d892f68ce77198812fccbeabfb79f97ce36688 Git commit a5f463e236639370ba2770b7bc0e28dbe777b0eb by Ilya Bizyaev, on behalf of Ilya Bizyaev. Committed on 30/01/2024 at 11:44. Pushed by ilyabizyaev into branch 'Plasma/6.0'. Fix display of multiline menu items Currently, multiline text in menu items is displayed incorrectly: the bounding rectangle is calculated ignoring newlines, while the newline is displayed in the resulting menu, and the text is cropped. This commit makes it so the newline is considered in the calculation as well. To do so, we get text metrics ourselves instead of delegating it to the ancient QMenu code that forces `Qt::TextSingleLine`. Note that this approach is not new: * In Breeze, the code right below for QStyleOptionMenuItem::Separator also gets text metrics. * In Qt, the Fusion style also requests font metrics: https://invent.kde.org/qt/qt/qtbase/-/blob/dev/src/widgets/styles/qfusionstyle.cpp#L3084-3088 Note that this commit does not imply that it is a good idea to use multiline menu item text in KDE apps from now on; it merely fixes an existing rendering defect that caused multiline actions to look wrong in StatusNotifierItems. (cherry picked from commit 7c5809b6dacc56d3c10893c68fb702278f7717ce) M +10 -2 kstyle/breezestyle.cpp https://invent.kde.org/plasma/breeze/-/commit/a5f463e236639370ba2770b7bc0e28dbe777b0eb |