zoukankan      html  css  js  c++  java
  • QtGui.QCheckBox

    QtGui.QCheckBox is a widget that has two states: on and off. It is a box with a label. Check boxes are typically used to represent features in an application that can be enabled or disabled.

    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    
    """
    ZetCode PyQt4 tutorial 
    
    In this example, a QtGui.QCheckBox widget
    is used to toggle the title of a window.
    
    author: Jan Bodnar
    website: zetcode.com 
    last edited: September 2011
    """
    
    import sys
    from PyQt4 import QtGui, QtCore
    
    class Example(QtGui.QWidget):
        
        def __init__(self):
            super(Example, self).__init__()
            
            self.initUI()
            
        def initUI(self):      
    
            cb = QtGui.QCheckBox('Show title', self)
            cb.move(20, 20)
            cb.toggle()
            cb.stateChanged.connect(self.changeTitle)
            
            self.setGeometry(300, 300, 250, 150)
            self.setWindowTitle('QtGui.QCheckBox')
            self.show()
            
        def changeTitle(self, state):
          
            if state == QtCore.Qt.Checked:
                self.setWindowTitle('QtGui.QCheckBox')
            else:
                self.setWindowTitle('')
            
    def main():
        
        app = QtGui.QApplication(sys.argv)
        ex = Example()
        sys.exit(app.exec_())
    
    
    if __name__ == '__main__':
        main()
    

    In our example, we will create a checkbox that will toggle the window title.

    cb = QtGui.QCheckBox('Show title', self)
    

    This is a QtGui.QCheckBox constructor.

    cb.toggle()
    

    We have set the window title, so we must also check the checkbox. By default, the window title is not set and the checkbox is unchecked.

    cb.stateChanged.connect(self.changeTitle)
    

    We connect the user defined changeTitle() method to the stateChanged signal. The changeTitle()method will toggle the window title.

    def changeTitle(self, state):
      
        if state == QtCore.Qt.Checked:
            self.setWindowTitle('QtGui.QCheckBox')
        else:
            self.setWindowTitle('')
    

    The state of the widget is given to the changeTitle() method in the state variable. If the widget is checked, we set a title of the window. Otherwise, we set an empty string to the titlebar.

    QtGui.QCheckBoxFigure: QtGui.QCheckBox

  • 相关阅读:
    小程序ArrayBuffer转JSON
    梅林路由修改hosts
    小程序半屏弹窗(Half Screen Dialog)插槽(Slot)无效的解决方法
    [小程序]存在将未绑定在 WXML 的变量传入 setData 的解决方法!
    小程序scroll-view指定高度
    修改小程序mp-halfScreenDialog组件高度
    小程序图片懒加载组件 mina-lazy-image
    OpenCOLLADA v1.6.68 MAYA MAX 全文件
    位运算相关知识
    全排列 next_permutation() 函数
  • 原文地址:https://www.cnblogs.com/hushaojun/p/4435744.html
Copyright © 2011-2022 走看看