码迷,mamicode.com
首页 > Windows程序 > 详细

Showing a tooltip

时间:2015-04-17 13:17:01      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

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 window and a button

author: Jan Bodnar
website: zetcode.com 
last edited: October 2011
"""

import sys
from PyQt4 import QtGui


class Example(QtGui.QWidget):
    
    def __init__(self):
        super(Example, self).__init__()
        
        self.initUI()
        
    def initUI(self):
        
        QtGui.QToolTip.setFont(QtGui.QFont(‘SansSerif‘, 10))
        
        self.setToolTip(‘This is a <b>QWidget</b> widget‘)
        
        btn = QtGui.QPushButton(‘Button‘, self)
        btn.setToolTip(‘This is a <b>QPushButton</b> widget‘)
        btn.resize(btn.sizeHint())
        btn.move(50, 50)       
        
        self.setGeometry(300, 300, 250, 150)
        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 two 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 being resized and moved on the window. The sizeHint() method gives a recommended size for the button.

技术分享Figure: Tooltip

Showing a tooltip

标签:

原文地址:http://www.cnblogs.com/hushaojun/p/4434564.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!