We can provide a balloon help for any of our widgets.
#!/usr/bin/python#-*-coding:utf-8-*-"" "Zetcode PyQt4 Tutorial This example shows a tooltip on a wind ow and a Buttonauthor:jan Bodnarwebsite:zetcode.com last Edited:october "" "Import sysfrom PyQt4 import Qtguiclass E Xample (qtgui.qwidget): def __init__ (self): Super (Example, self). __init__ () Self.initui () def initui (self): QtGui.QToolTip.setFont (Qtgui.qfont (' Sansserif ', ten)) Self.settoolti P (' This was a <b>QWidget</b> widget ') btn = Qtgui.qpushbutton (' Button ', self) btn.settool Tip (' This is a <b>QPushButton</b> widget ') btn.resize (Btn.sizehint ()) Btn.move (50, 50) Self.setgeometry (() self.setwindowtitle (' ToolTips ') self.show () def Main (): App = Qtgui.qapplication (sys.argv) ex = Example () sys.exit (APP.EXEC_ ()) If __name__ = = ' __main__ ': Main ()
In this example, we show a tooltip for the PyQt4 widgets.
QtGui.QToolTip.setFont (Qtgui.qfont (' Sansserif ', 10))
This static method sets a font used to render tooltips. We use a 10px sansserif font.
Self.settooltip (' This is a <b>QWidget</b> widget ')
To create a ToolTip, we call the setTooltip() method. We can also use rich text formatting.
BTN = Qtgui.qpushbutton (' Button ', self) btn.settooltip (' This is a <b>QPushButton</b> widget ')
We Create a button widget and set a ToolTip for it.
Btn.resize (Btn.sizehint ()) Btn.move (50, 50)
The button is a being resized and moved on the window. The sizeHint() method gives a recommended size for the button.
Figure:tooltip
Showing a ToolTip