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.

Figure: QtGui.QCheckBox

QtGui.QCheckBox的更多相关文章

  1. PyQt4单选框QCheckBox

    PyQt4中的部件 部件是构建应用程序的基础元素.PyQt4工具包拥有大量的种类繁多的部件.比如:按钮,单选框,滑块,列表框等任何程序员在完成其工作时需要的部件. QCheckBox单选框 单选框具有 ...

  2. Pyqt 获取打包二进制文件中的资源

    记得有一次打开一个单独exe程序,点击btn中的一个帮助说明按钮,在同级目录下就多出一个help.chm 文件并自动打开. 那这个exe肯定是把help.chm 打包到exe中,当我触发“帮助”按钮的 ...

  3. Pyqt 屏幕截图工具

    从Pyqt的examples中看到一段截图代码, (路径:examplas\desktop\screenshot.py) 所以想自己UI下界面,手动练习下 通过UI生成的: Screenshot.py ...

  4. Pyqt Smtplib实现Qthread多线程发送邮件

    一. smtplib 的介绍 smtplib.SMTP([host[, port[, local_hostname[, timeout]]]])   SMTP类构造函数,表示与SMTP服务器之间的连接 ...

  5. Pyqt QSystemTrayIcon 实现托盘效果

    pyqt的托盘效果很好实现,在Pyqt的demo中有个例子 路径:PyQt4\examples\desktop\systray.py 今天我就仿这个Tray效果做效果 一. 创建UI trayicon ...

  6. pyqt小例子 音乐盒

    源代码1: # -*- coding: utf-8 -*- import sys,time,os import ctypes from PyQt4 import QtCore, QtGui,Qt fr ...

  7. PYQT4 : QSystemTrayIcon练习

    照着demo自己做了一遍,练练手 import sys from PyQt4 import QtGui from PyQt4 import QtCore class SysTray(QtGui.QDi ...

  8. Python&MySQL&PyQt

    环境: Python2.7+MySQL5.6+PyQt4 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/40 ...

  9. PyQt4 的部件 -- CheckBox 单选框

    单选框具有两种状态:被选中或未被选中. 当用户选择或者取消选择时,单选框就会发射一个stateChanged()信号 # QCheckBox 单选框 # 本例创建一个用来改变窗口标题的单选框 impo ...

随机推荐

  1. 51nod 1412 AVL树的种类

    非常简单的一道题,一眼题 枚举左儿子大小,再枚举深度即可 复杂度$O(n^2 log n)$ #include <cstdio> #include <cstring> #inc ...

  2. 【尺取法】POJ3061 & POJ3320

    POJ3061-Subsequence [题目大意] 给定长度微n的数列整数及整数s.求出总和不小于s的连续子序列的长度的最小值.如果节不存在,则输出0. [思路] 尺取法五分钟裸裸裸~刷水刷出了罪恶 ...

  3. 【动态规划/多重背包问题】POJ2392-Space Elevator

    方法同POJ1014-Dividing,唯一不同点在于每一种block有最大限定高度a,故要以a为关键字进行排序,使得最大高度小的在前,否则最大高度小的再后可能放不上去. #include<io ...

  4. python开发_bisect

    现在有如下的需求: ''' 实现这样的一个功能: 对一个班级的学生的成绩做出一些评定,评定规则是: one: [0-60) -- F two: [60-70) -- D three: [70-80) ...

  5. window10下java环境变量的配置 javac不是内部或外部命令的问题

    http://blog.csdn.net/suncold123/article/details/48392135 参考与上面这个博主. 今天在win10下重新配置了一下java环境变量.跟着网上的流程 ...

  6. Si4455 低电流 Sub-GHz收发器

    Silicon Labs 的 Si4455 是易于使用的低电流 Sub-GHz EZRadio® 收发器.覆盖所有主要波段,结合了即插即用的简单性和需要处理各种不同应用的灵活性.紧凑的 3 mm x ...

  7. PHP中var_dump

    var_dump() 能打印出类型 print_r() 只能打出值echo() 是正常输出... 需要精确调试的时候用 var_dump();一般查看的时候用 print_r() 另外 , echo不 ...

  8. Fiddler2 抓取手机APP数据包

    原文:http://blog.goyiyo.com/archives/2044 下载安装运行后,查出运行机器的IP,手机连接同一网域内的WIFI,手机WIFI连接设置里的高级里,代理设置填写上Fidd ...

  9. Host 'localhost' has multiple addresses. 解决办法

    phpstorm调试php 错误提示: Host 'localhost' has multiple addresses. You must choose one explicitly!Couldn't ...

  10. iOS: sqlite数据库的基本操作

    介绍: sqlite3(3是版本)是本地系统中的一个小型数据库,因为它没有在数据维护和安全上做过多的操作,所以它存储处理数据时,非常简单方便,但是它是不安全和不可靠的,如果一旦误操作删除了数据,是没有 ...