Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
dockWidget toggleViewAction and mnemonic handling
Just upgraded from 5.12 to 5.14.2 on Windows and I notice a welcome patch that fixes the dock window title handling on fusion styling (and perhaps other styles) w.r.t. mnemonics. On 5.12, prior to the 5.14 upgrade, when issuing the api below, I would get a title with the typical shortcut rendering (ampersand becomes an underlined char). So that's fixed, great, but ...
dock_widget->setWindowTitle("This & That");
I also have a very typical "View" menu in which I have added a dock widget toggle via:
This is a nice feature that gives you a free checkbox in the view menu for that dock widget. The problem, however, is that view menu action follows the dock widget's title, but uses the mnemonic interpretation of the title and converts the ampersand to a shortcut. It's something I want to turn off for that particular action.
My workaround is to connect to the view menu's
aboutToShowsignal and do this:
QString title_no_mnemonic = dock_widget->windowTitle().replace("&", "&&"); dock_widget_toggle_action->setText(title_no_mnemonic);
Not sure if this is a reasonable way to do this, but perhaps the dockWidget's
toggleViewActionshould implicitly be free of such shortcut handling?
From the top of my head, shouldn't you use two ampersands in that case ?
@SGaist You mean in the
That api (happily) no longer converts mnemonics, so doubling the ampersand produces two ampersands in the display. No, the issue is that
QDockWidget::toggleViewActionproduces a QAction which does not do the same, i.e. it does convert mnemonics, so there is a lack of consistent treatment of window titles -- on the one hand I do not have to double-up (
QDockWidget::setWindowTitle), but on the other hand I do have to double-up the ampersands (
Well, these two have different purposes so you cannot expect "consistency" here.
It might be something that QDockWidget should do for you but it's not QAction's rôle to do that.
Did you check the bug report system for something related ?
@SGaist I just checked and here is the code review and associated bug to the change I observed in my OP where the dock window title no longer tries to make mnemonic shortcuts. My issue, then, is a follow-on to that correction -- the QAction returned from
QDockWidget::toggleViewActionshould also ignore mnemonics since the only context in which the text of this action might be used would be for display of the title. There must be a
QAction::setTexthappening internally when the dock widget title changes and perhaps that code might also be patched.