Results 1 to 6 of 6

Thread: Newbie Trying to Create a Menu ToolTip, but setToolTip() Doesn't Seem to Work

  1. #1
    Join Date
    May 2015
    Posts
    5
    Qt products
    PyQt3 PyQt4
    Platforms
    Windows

    Default Newbie Trying to Create a Menu ToolTip, but setToolTip() Doesn't Seem to Work

    Hello. I was trying to set the tooltip for a menu item, but setToolTip() doesn't seem to work. According to the documentation:

    "The simplest and most common way to set a widget's tool tip is by calling its QWidget::setToolTip() function."

    What am I doing wrong here?

    import sys
    from PyQt4.QtGui import *
    from PyQt4.QtCore import *

    app=QApplication(sys.argv)
    w=QMainWindow()
    w.resize(600,400)
    w.setWindowTitle("Hello World")

    mainMenu=w.menuBar()
    fileMenu=mainMenu.addMenu('&File')

    exitButton=QAction(QIcon('exit24.png'),'Exit',w)
    exitButton.setShortcut('Ctrl+Q')
    exitButton.setToolTip('Exit')
    exitButton.triggered.connect(w.close)
    fileMenu.addAction(exitButton)

    fileMenu=mainMenu.addMenu('&Edit')

    w.show()
    sys.exit(app.exec_())

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Newbie Trying to Create a Menu ToolTip, but setToolTip() Doesn't Seem to Work

    How does "doesn't seem to work" manifest itself?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2015
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Newbie Trying to Create a Menu ToolTip, but setToolTip() Doesn't Seem to Work

    Hello sinefine,

    What I think your problem might be is that although your file "exit24.png" might be located in the folder that the source code is in, when you run the program in "Debug" or "Release" mode, your file does not exist in the folder that it is being compiled to. You need to use a Qt Resource file, add this file into the Qt Resource file and then make reference to the path of the Qt Resource file.

    QAction(QIcon(':/pathwheremyresourcefilestoresthisfile/exit24.png'),'Exit',w)

  4. #4
    Join Date
    May 2015
    Posts
    5
    Qt products
    PyQt3 PyQt4
    Platforms
    Windows

    Default Re: Newbie Trying to Create a Menu ToolTip, but setToolTip() Doesn't Seem to Work

    Quote Originally Posted by wysota View Post
    How does "doesn't seem to work" manifest itself?
    It manifests itself because when I hover mouse over the menu item, nothing shows up.


    Quote Originally Posted by chris.kzn View Post
    Hello sinefine,

    What I think your problem might be is that although your file "exit24.png" might be located in the folder that the source code is in, when you run the program in "Debug" or "Release" mode, your file does not exist in the folder that it is being compiled to. You need to use a Qt Resource file, add this file into the Qt Resource file and then make reference to the path of the Qt Resource file.

    QAction(QIcon(':/pathwheremyresourcefilestoresthisfile/exit24.png'),'Exit',w)
    I will try that. Thank you, sir!

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Newbie Trying to Create a Menu ToolTip, but setToolTip() Doesn't Seem to Work

    Quote Originally Posted by sinefine View Post
    It manifests itself because when I hover mouse over the menu item, nothing shows up.
    Do they show up when you hover your mouse over menu entries in other programs? I don't think tooltips are used in menu entries anywhere. You would probably have to implement such behavior yourself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    May 2015
    Posts
    5
    Qt products
    PyQt3 PyQt4
    Platforms
    Windows

    Default Re: Newbie Trying to Create a Menu ToolTip, but setToolTip() Doesn't Seem to Work

    Quote Originally Posted by wysota View Post
    Do they show up when you hover your mouse over menu entries in other programs? I don't think tooltips are used in menu entries anywhere. You would probably have to implement such behavior yourself.
    Okay. Thank you!

Similar Threads

  1. QSqlQuery Create View query doesn't work
    By jiansheng03 in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2013, 21:24
  2. Tray menu doesn't work on Mac
    By skruffynerherder in forum Newbie
    Replies: 4
    Last Post: 14th March 2013, 23:03
  3. Replies: 7
    Last Post: 29th November 2010, 19:20
  4. QGraphicsItem::setToolTip does not work
    By Nadia in forum Qt Programming
    Replies: 2
    Last Post: 6th September 2009, 19:54
  5. WindowsXP : menu items activated() doesn't work
    By Valheru in forum Qt Programming
    Replies: 2
    Last Post: 10th October 2006, 13:21

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.