Important: Please read the Qt Code of Conduct -

Menu item with mnemonic gets cut off

  • 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:


    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):
            menu_bar = QtWidgets.QMenuBar()
            submenu = menu_bar.addMenu('&View')
            qaction = QtGui.QAction(TXT, self)
            qaction = QtGui.QAction(TXT_PLAIN, self)
            # Uncomment for correct text items:
            #qaction = QtGui.QAction(TXT_PLAIN + ' longer', self)
            # 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,
    app = QtWidgets.QApplication(sys.argv)
    win = MainWindow(app)

    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?

  • Lifetime Qt Champion


    Looks fishy...

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

  • 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...

  • Lifetime Qt Champion

    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.

  • 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.

Log in to reply