Results 1 to 2 of 2

Thread: Tooltips on QActions

  1. #1
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Red face Tooltips on QActions

    Hi,

    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

    Qt Code:
    1. #include <QApplication>
    2. #include <QMenuBar>
    3. #include <QAction>
    4.  
    5. int main( int argc, char **argv )
    6. {
    7. QApplication app( argc, argv );
    8. QMenuBar *bar = new QMenuBar();
    9. QAction *action = bar->addAction("my action");
    10. action->setToolTip("my tooltip");
    11.  
    12. bar->show();
    13.  
    14. return app.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Tooltips on QActions

    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.

Similar Threads

  1. Replies: 1
    Last Post: 18th December 2008, 10:25
  2. QActions don't work with menubar hidden
    By Pepe in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2007, 01:04
  3. Problems with QActions and Pixmaps
    By ToddAtWSU in forum Qt Programming
    Replies: 8
    Last Post: 11th April 2007, 21:53
  4. toolTips?
    By mickey in forum Qt Programming
    Replies: 11
    Last Post: 23rd February 2006, 19:10
  5. Tooltips & Qt4 tree views
    By yogeshm02 in forum Newbie
    Replies: 7
    Last Post: 17th January 2006, 15:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.