Showing a ToolTip

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.