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

  • 相关阅读:
    addEventListener-第三个参数 useCapture
    介绍(javascript调试)
    Linux_PXE服务器_RHEL7
    Linux_PXE服务器_RHEL7
    Linux_OpenSSH远程连接
    Linux_OpenSSH远程连接
    Python基本语法_强制数据类型转换
    Python基本语法_强制数据类型转换
    Linux_NetworkManager_RHEL7
    Linux_NetworkManager_RHEL7
  • 原文地址:https://www.cnblogs.com/hushaojun/p/4434564.html
Copyright © 2011-2022 走看看