I have QActions
added to a QToolBar
using addAction()
.
I want the toolbar button tooltips to show the shortcuts. e.g. Copy (Ctrl+C). Of course, i could statically set
action->setTooltip(QString("%1 (%2)").arg(action.toolTip(), action->shortcut().toString(QKeySequence::NativeText)));
However, this is quite cumbersome because there are lots of actions and the user can modify the shortcuts so that I would have to keep track of that and update accordingly. It would be much nicer if I could simply modify the QToolBar
tooltip behavior by subclassing QToolBar
similar to http://doc.qt.io/qt-5/qtwidgets-widgets-tooltips-example.html.
Unfortunately, it's not that simple. The tooltip is not generated by the QToolBar
itself, but apparently by a QToolButton
which is created internally when using addAction()
. So ideally I would inject my own subclass of QToolButton
. But that seems imposible because the actual instantiation of the toolbutton is done inside the private QToolBarLayout which I cannot access.
Any ideas how to solve this?