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

  • 相关阅读:
    「UVA12293」 Box Game
    「CF803C」 Maximal GCD
    「CF525D」Arthur and Walls
    「CF442C」 Artem and Array
    LeetCode lcci 16.03 交点
    LeetCode 1305 两棵二叉搜索树中的所有元素
    LeetCode 1040 移动石子直到连续 II
    LeetCode 664 奇怪的打印机
    iOS UIPageViewController系统方法崩溃修复
    LeetCode 334 递增的三元子序列
  • 原文地址:https://www.cnblogs.com/hushaojun/p/4434564.html
Copyright © 2011-2022 走看看