Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Menu item with mnemonic gets cut off
QtWS25 Last Chance

Menu item with mnemonic gets cut off

Scheduled Pinned Locked Moved Unsolved Qt 6
5 Posts 2 Posters 633 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    le_becc
    wrote on last edited by
    #1

    I'm not sure whether this is specific to Qt6, but that's what I'm on. When my longest menu item has a mnemonic, it gets shortened while the same item without mnemonics gets displayed fully:

    screenshot_menu_cutoff.png

    Once there's another item in the menu that's longer, everything is fine.

    I'm on Debian Linux+Gnome+XOrg. Tthis is my example in PyQt:

    import sys
    from PyQt6 import QtGui, QtWidgets
    from PyQt6.QtCore import Qt
    
    TXT = '&Show Scrollbars'
    TXT_PLAIN = 'Show Scrollbars'
    
    class MainWindow(QtWidgets.QMainWindow):
        def __init__(self, app):
            super().__init__()
            menu_bar = QtWidgets.QMenuBar()
            submenu = menu_bar.addMenu('&View')
    
            qaction = QtGui.QAction(TXT, self)
            submenu.addAction(qaction)
    
            qaction = QtGui.QAction(TXT_PLAIN, self)
            submenu.addAction(qaction)
    
            # Uncomment for correct text items:
            #qaction = QtGui.QAction(TXT_PLAIN + ' longer', self)
            #submenu.addAction(qaction)
    
            menu_bar.addMenu(submenu)
            self.setMenuBar(menu_bar)
            self.show()
    
            # Some debug output:
            fm = QtGui.QFontMetrics(QtGui.QFont())
            width = fm.size(Qt.TextFlag.TextHideMnemonic, TXT).width()
            width_mn = fm.size(Qt.TextFlag.TextShowMnemonic, TXT).width()
            width_plain = fm.size(Qt.TextFlag.TextHideMnemonic, TXT_PLAIN).width()
            width_plain_mn = fm.size(Qt.TextFlag.TextShowMnemonic, TXT_PLAIN).width()
            print(width, width_mn, width_plain, width_plain_mn)
            print(fm.elidedText(TXT, Qt.TextElideMode.ElideMiddle, width_mn,
                                Qt.TextFlag.TextShowMnemonic))
    
    app = QtWidgets.QApplication(sys.argv)
    win = MainWindow(app)
    app.exec()
    

    I've been playing around with elidedText manually, but everything works as expected and all the text length are the same, regardless of mnemonic. Here's the debug output:

    108 108 108 108
    &Show Scrollbars
    

    Anyone knows what's up?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Looks fishy...

      Which version of PySide6 are you using ?
      On which platform ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        le_becc
        wrote on last edited by
        #3

        I'm on Debian Linux+Gnome+XOrg. I'm currently on PyQt 6.2, but this has been happening in 6.1 as well, and maybe even 6.0. I don't remember exactly when I added this menu...

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Testing the same application with PySide2 does not exhibit this behaviour.

          You should check the bug report system to see if it's something known. If not, please open a new ticket providing your script and finding.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • L Offline
            L Offline
            le_becc
            wrote on last edited by
            #5

            Thanks for the reply! I looked at the bug tracker before posting here, but I looked again and I was more lucky this time. Seems like it's this bug.

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved