Qt World Summit: Submit your Presentation

[Solved] Tooltip on QAction

  • I am using Qt designer. In dialogs I could set the tool tip for QLineEdit and other widgets. As far as I remember there was no additional code required. Now I have a QMenuBar with QMenu and QActions all designed with Qt Designer. I have tried to use the tool tip, but it does not work.
    The examples I have found show that one has to implement the event. But those menus are set up manually. Do I really have to setup teh event handling? Or do I miss something which is needed to be activated?

  • It seems you can only set tool tips for submenu (QMenu), not menu items (QAction), but when the menu item is hovered, the QAction statusTip text will be displayed in the status bar, if there is one.

    QAction tool tips are displayed if you add the QAction to a QToolBar.

    There is no code to handle tool tips in QMenu. Since the code to show the tool tip, in QApplication, is triggered when you enter and hover a QWidget, and QMenu doesn't use sub-widgets to display the items but draws them directly (unlike QToolBar which create QToolButtons when you add the QAction to it), you would probably have to implement it manually, if you really want that feature.

  • Thanks for your reply.
    statusTip I had used already and that does work. However, the whole display, the design is for, is quite small. My menus are sometimes covering the statusBar and, therefore, covering the text. That is the reason for looking for the toolTip.
    It is a little confusing, when something works without almost no effort in one configuration, but not in the other.

  • Extremely helpful post. Thank you for posting this. I, too, find it strange and inconvenient that my QAction tooltips appear everywhere except in QMenus, especially since Designer doesn't give easy access to statusTips. It was so unexpected that it took me months to even notice that the tooltips weren't displaying! Thanks for the workaround.

  • Since status tips aren't conveniently added to QActions in Qt Designer, I wound up adding this to my MainWindow constructor to copy my tooltips to the statustips for the QActions that also happen to be in my menu tree.

    @QList<QMenu*> menulist(ui->menuBar->findChildren<QMenu*>());
    for(int mnum = 0; mnum < menulist.size(); ++mnum)
    QList<QAction*> actionlist(menulist.at(mnum)->actions());
    for(int actnum = 0; actnum < actionlist.size(); ++actnum)

Log in to reply