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_())
Re: Newbie Trying to Create a Menu ToolTip, but setToolTip() Doesn't Seem to Work
How does "doesn't seem to work" manifest itself?
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)
Re: Newbie Trying to Create a Menu ToolTip, but setToolTip() Doesn't Seem to Work
Quote:
Originally Posted by
wysota
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
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!
Re: Newbie Trying to Create a Menu ToolTip, but setToolTip() Doesn't Seem to Work
Quote:
Originally Posted by
sinefine
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.
Re: Newbie Trying to Create a Menu ToolTip, but setToolTip() Doesn't Seem to Work
Quote:
Originally Posted by
wysota
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!