????在使用pycharm進(jìn)行編寫代碼的時候,發(fā)現(xiàn)信號設(shè)置了connect一個槽,但是測試發(fā)現(xiàn)沒有起作用,另外,在pycharm編輯器上connect提示沒有這個函數(shù),總是找不到原因,后面決定還是對碰到相應(yīng)的知識點需要做對應(yīng)的測試用例進(jìn)行學(xué)習(xí)和驗證。
公司主營業(yè)務(wù):做網(wǎng)站、網(wǎng)站制作、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)建站是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)建站推出汕頭免費做網(wǎng)站回饋大家。
????下面這個是對信號+槽的一個典型實例??梢哉0搭A(yù)期運行,在pycharm中connect也顯示沒有這個函數(shù),應(yīng)該就是pycharm本身設(shè)置和提示的問題,后面忽略它。所以有時候也不能鉆牛角尖,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("保存狀態(tài):") ????????self.saveLabel?=?QLabel() ????????self.label2?=?QLabel("運行狀態(tài):") ????????self.runLabel?=?QLabel() ????????self.buttonSave?=?QPushButton("保存") ????????self.buttonRun?=?QPushButton("運行") ????????self.buttonStop?=?QPushButton("停止") ????????self.buttonDisconnect?=?QPushButton("解除關(guān)聯(lián)") ????????self.buttonConnect?=?QPushButton("綁定關(guān)聯(lián)") ????????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_())