PyQt5--QCheckBox

2020-01-19 11:21:34 浏览数 (1)

代码语言:javascript复制
 1 # -*- coding:utf-8 -*-
 2 '''
 3 Created on Sep 20, 2018
 4 
 5 @author: SaShuangYiBing
 6 
 7 Comment: 
 8 '''
 9 import sys
10 from PyQt5.QtCore import Qt
11 from PyQt5.QtWidgets import QApplication,QWidget,QCheckBox
12 
13 class New_test(QWidget):
14     def __init__(self):
15         super().__init__()
16         self.initUI()
17         
18     def initUI(self):
19         cb = QCheckBox('Show Title',self)
20         cb.move(20,20)
21         cb.toggle()  # 因为前面已经设置了标题,所以这里就需要先将checkbox默认勾上,否则会导致和一次时标题与复选框状态对不上
22         cb.stateChanged.connect(self.changeTitle)  # 将复选框的状态改变信号连接到自定义的槽函数changeTitle上
23         
24         self.setGeometry(300,300,250,150)
25         self.setWindowTitle('QCheck Box')
26         self.show()
27         
28     def changeTitle(self,state):
29         if state == Qt.Checked:
30             self.setWindowTitle('QCheck Box')
31         else:
32             self.setWindowTitle('')
33             
34 if __name__ == '__main__':
35     app = QApplication(sys.argv)
36     ex = New_test()
37     sys.exit(app.exec_())

复选框默认勾上的标题

取消勾选的标题提示

0 人点赞