Qt has several different built-in APIs for showing help messages to the user, so I would suggest you give consideration to these before trying to roll your own solution:
- For simple a message that describes what the GUI element is, you can set a tooltip.
- For slightly longer messages that describe what a GUI element does, you can set a status tip. These are most often used for menu items and toolbar buttons.
- For longer, more informative messages, you can use what's this mode. These messages can make use of html formatting, and can also include links to the main help.
The demo script below uses all these methods, and also shows how to handle links in "what's this" messages:
from PyQt4 import QtCore, QtGui
class Window(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.statusBar()
self.toolbar = self.addToolBar('toolbar')
action = QtGui.QWhatsThis.createAction(self)
action.setStatusTip('Enter what\'s this mode')
self.toolbar.addAction(action)
widget = QtGui.QGroupBox(self)
layout = QtGui.QVBoxLayout(widget)
self.setCentralWidget(widget)
for name in 'one two three four'.split():
checkbox = QtGui.QCheckBox('Checkbox %s' % name, self)
checkbox.setToolTip('Tooltip for checkbox %s' % name)
checkbox.setWhatsThis("""
<b>What\'s this text</b>:<br><br>
Checkbox %s<br><br>
<a href="url-%s">link to main help</a>
""" % (name, name))
checkbox.installEventFilter(self)
layout.addWidget(checkbox)
def eventFilter(self, source, event):
if event.type() == QtCore.QEvent.WhatsThisClicked:
print(event.href())
return QtGui.QMainWindow.eventFilter(self, source, event)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.setGeometry(500, 300, 250, 200)
window.show()
sys.exit(app.exec_())