Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-115356

QMenu clips text for actions with icons with larger fonts

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.2.4, 6.3.1
    • Widgets: Style Sheets
    • None
    • All

    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:

      1. define QMenu and populate it with actions with icons
      2. set stylesheet with "QMenu::item { font-size: 21px; }"
      3. create a window, add QToolButton and add menu to it
      4. open the menu and enjoy the text being clipped

      This happens as soon as at least one item in menu has an icon

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            chehrlic Christian Ehrlicher
            nrub Michał Kaczorowski
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change