pyqt5之信号+槽测试用例
在使用pycharm进行编写代码的时候,发现信号设置了connect一个槽,但是测试发现没有起作用,另外,在pycharm编辑器上connect提示没有这个函数,总是找不到原因,后面决定还是对碰到相应的知识点需要做对应的测试用例进行学习和验证。
公司主营业务:做网站、网站制作、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联建站是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联建站推出汕头免费做网站回馈大家。
下面这个是对信号+槽的一个典型实例。可以正常按预期运行,在pycharm中connect也显示没有这个函数,应该就是pycharm本身设置和提示的问题,后面忽略它。所以有时候也不能钻牛角尖,pycharm也仅仅是个编辑器而已。
#-*- coding:utf-8 -*- ''' Signal & Slot ''' __author__ = 'Tony Zhu' import sys from PyQt5.QtCore import Qt from PyQt5.QtWidgets import (QWidget, QLcdnumber, QSlider,QGridLayout,QLabel,QHBoxLayout, QGroupBox, QVBoxLayout, QApplication,QProgressBar,QPushButton,QMessageBox) class SignalSlot(QWidget): def __init__(self): super(SignalSlot,self).__init__() self.initUI() def initUI(self): self.controlsGroup = QGroupBox("运行样本") self.lcdNumber = QLCDNumber(self) self.slider = QSlider(Qt.Horizontal, self) self.pBar = QProgressBar(self) vbox = QVBoxLayout() vbox.addWidget(self.pBar) vbox.addWidget(self.lcdNumber) vbox.addWidget(self.slider) self.controlsGroup.setLayout(vbox) controlsLayout = QGridLayout() self.label1 = QLabel("保存状态:") self.saveLabel = QLabel() self.label2 = QLabel("运行状态:") self.runLabel = QLabel() self.buttonSave = QPushButton("保存") self.buttonRun = QPushButton("运行") self.buttonStop = QPushButton("停止") self.buttonDisconnect = QPushButton("解除关联") self.buttonConnect = QPushButton("绑定关联") controlsLayout.addWidget(self.label1,0,0) controlsLayout.addWidget(self.saveLabel,0,1) controlsLayout.addWidget(self.label2,1,0) controlsLayout.addWidget(self.runLabel,1,1) controlsLayout.addWidget(self.buttonSave,2,0) controlsLayout.addWidget(self.buttonRun,2,1) controlsLayout.addWidget(self.buttonStop,2,2) controlsLayout.addWidget(self.buttonDisconnect,3,0) controlsLayout.addWidget(self.buttonConnect,3,1) layout = QHBoxLayout() layout.addWidget(self.controlsGroup) layout.addLayout(controlsLayout) self.setLayout(layout) self.buttonRun.clicked.connect(self.buttonSave.clicked) self.slider.valueChanged.connect(self.pBar.setValue) self.slider.valueChanged.connect(self.lcdNumber.display) self.buttonSave.clicked.connect(self.showMessage) self.buttonRun.clicked.connect(self.showMessage) self.buttonDisconnect.clicked.connect(self.unbindConnection) self.buttonConnect.clicked.connect(self.bindConnection) self.buttonStop.clicked.connect(self.stop) self.setGeometry(300, 500, 500, 180) self.setWindowTitle('信号和槽') def showMessage(self): if self.sender().text() == "保存": self.saveLabel.setText("Saved") elif self.sender().text() == "运行": self.saveLabel.setText("Saved") self.runLabel.setText("Running") def unbindConnection(self): self.slider.valueChanged.disconnect() def bindConnection(self): self.slider.valueChanged.connect(self.pBar.setValue) self.slider.valueChanged.connect(self.lcdNumber.display) def stop(self): self.saveLabel.setText("") self.runLabel.setText("") if __name__ == '__main__': app = QApplication(sys.argv) ex = SignalSlot() ex.show() sys.exit(app.exec_())
本文题目:pyqt5之信号+槽测试用例
当前网址:http://azwzsj.com/article/johjso.html