|
楼主 |
发表于 2016-11-12 18:08:49
|
显示全部楼层
PyQt4 designer checkBox使用
第一图,先拖入checkBox,和标签
第二图,给checkBox添加触发信号。生成程序里面就是这个“QtCore.QObject.connect(self.checkBox, QtCore.SIGNAL(_fromUtf8("clicked()")), Form.slotcheck)”
生成的代码如下
- # -*- coding: utf-8 -*-
- # Form implementation generated from reading ui file 'untitled.ui'
- #
- # Created by: PyQt4 UI code generator 4.11.4
- #
- # WARNING! All changes made in this file will be lost!
- from PyQt4 import QtCore, QtGui
- try:
- _fromUtf8 = QtCore.QString.fromUtf8
- except AttributeError:
- def _fromUtf8(s):
- return s
- try:
- _encoding = QtGui.QApplication.UnicodeUTF8
- def _translate(context, text, disambig):
- return QtGui.QApplication.translate(context, text, disambig, _encoding)
- except AttributeError:
- def _translate(context, text, disambig):
- return QtGui.QApplication.translate(context, text, disambig)
- class Ui_Form(object):
- def setupUi(self, Form):
- Form.setObjectName(_fromUtf8("Form"))
- Form.resize(400, 300)
- self.checkBox = QtGui.QCheckBox(Form)
- self.checkBox.setGeometry(QtCore.QRect(190, 170, 71, 20))
- self.checkBox.setObjectName(_fromUtf8("checkBox"))
- self.label = QtGui.QLabel(Form)
- self.label.setGeometry(QtCore.QRect(200, 130, 54, 12))
- self.label.setObjectName(_fromUtf8("label"))
- self.retranslateUi(Form)
- QtCore.QObject.connect(self.checkBox, QtCore.SIGNAL(_fromUtf8("clicked()")), Form.slotcheck)
- QtCore.QMetaObject.connectSlotsByName(Form)
- def retranslateUi(self, Form):
- Form.setWindowTitle(_translate("Form", "Form", None))
- self.checkBox.setText(_translate("Form", "CheckBox", None))
- self.label.setText(_translate("Form", "True", None))
复制代码
- # -*- coding: utf-8 -*-
- """
- Created on Sat Nov 12 15:18:31 2016
- @author: Administrator
- """
- from PyQt4.QtGui import *
- from PyQt4.QtCore import *
- import sys
- import untitled
- class TestDialog(QDialog,untitled.Ui_Form):
- def __init__(self,parent=None):
- super(TestDialog,self).__init__(parent)
- self.setupUi(self)
-
- def slotcheck(self):
- if self.checkBox.isChecked():
- self.label.setText("hello")
- else:
- self.label.setText("world")
-
-
-
-
- app = QApplication(sys.argv)
- dialog=TestDialog()
- dialog.show()
- app.exec_()
复制代码
调用的代码如上,这个就是对应的槽函数,里面就是一些信号响应后的操作。
- def slotcheck(self):
- if self.checkBox.isChecked():
- self.label.setText("hello")
- else:
- self.label.setText("world")
复制代码 |
|