zoukankan      html  css  js  c++  java
  • Showing a tooltip

    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.

    TooltipFigure: Tooltip

  • 相关阅读:
    一只特立独行的猪
    每天写出好代码的5个建议
    电脑修好了
    VB编程修改AutoCAD长度型尺寸标注
    前天我放学回家
    VB编程修改AutoCAD坐标型尺寸标注
    VB编程操作AutoCAD尺寸标注样式
    这是一个错误的程序
    2011年6月27日星期二
    2011年6月20日星期一
  • 原文地址:https://www.cnblogs.com/hushaojun/p/4434564.html
Copyright © 2011-2022 走看看