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): 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?
-
Hi,
Looks fishy...
Which version of PySide6 are you using ?
On which platform ? -
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.