View Full Version : Tooltips on QActions

6th February 2006, 21:53

In the short QT-4.1.0 example below, I'm putting a QAction inside a QMenuBar.
It gets shown all right, but if I pause the mouse pointer above the QAction, its
Tooltip is not shown. I have no problems with tooltips on classes that inherit from
QWidget, but what is needed for a QAction's tooltip to be displayed?

/Joakim Rosqvist

#include <QApplication>
#include <QMenuBar>
#include <QAction>

int main( int argc, char **argv )
QApplication app( argc, argv );
QMenuBar *bar = new QMenuBar();
QAction *action = bar->addAction("my action");
action->setToolTip("my tooltip");


return app.exec();

8th February 2006, 19:05
Solution found:

In order to show a tooltip on a QAction in a QMenuBar, one has to overload the
event() method on the QMenuBar and look for an event of type QEvent::Tooltip.
When it arrives, one can ask QMenuBar::activeAction() to know over which
QAction the mouse pointer is, and then finally call QToolTip::showText on that
QAction's tooltip.