当前位置:网站首页>(5) Pyqt5 ---- another method of connecting signals and slots
(5) Pyqt5 ---- another method of connecting signals and slots
2022-06-25 12:36:00 【haoming Hu】
GitHub Connect :
This column all source code GitHub Through train
It's a little strange
But after learning this way , I don't think it's that flexible, right , This will be mentioned later
Look at the code first
Main program code :
""" /******************************************************************************** * @Filename: Decorator signal and slot .py * @Author: haomingHu * @Version: 1.0 * @Date: 2020-12-16 * @Description: * @History: ********************************************************************************/ """
from ui4 import Ui_Form# Import on QTdesigner Well designed ui.py file
import sys
from PyQt5 import QtWidgets,QtCore
class mydesigner(QtWidgets.QWidget,Ui_Form):
def __init__(self):
super(mydesigner,self).__init__()
self.setupUi(self)
QtCore.QMetaObject.connectSlotsByName(self)
@QtCore.pyqtSlot()
def on_open_clicked(self):
self.calendarWidget.close()
@QtCore.pyqtSlot()
def on_close_clicked(self):
self.calendarWidget.show()
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
myshow = mydesigner()
myshow.show()
sys.exit(app.exec_())
ui File code :
""" /******************************************************************************** * @Filename: ui4.py * @Author: haomingHu * @Version: 1.0 * @Date: 2020-12-16 * @Description: * @History: ********************************************************************************/ """
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'ui4.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(432, 325)
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(40, 220, 75, 23))
self.pushButton.setObjectName("open")
self.pushButton_2 = QtWidgets.QPushButton(Form)
self.pushButton_2.setGeometry(QtCore.QRect(290, 220, 75, 23))
self.pushButton_2.setObjectName("close")
self.calendarWidget = QtWidgets.QCalendarWidget(Form)
self.calendarWidget.setGeometry(QtCore.QRect(80, 10, 248, 197))
self.calendarWidget.setObjectName("calendarWidget")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton.setText(_translate("Form", "PushButton"))
self.pushButton_2.setText(_translate("Form", "PushButton"))
Just look at the rest of the code , Look at the following lines of code :
@QtCore.pyqtSlot()
def on_open_clicked(self):
self.calendarWidget.close()
@QtCore.pyqtSlot()
def on_close_clicked(self):
self.calendarWidget.show()
First , The premise of using this method is to execute the following line of code first ,( This line of code is in setupUi The function has )
QtCore.QMetaObject.connectSlotsByName(Form)
This line of code is pyqt5 Automatically connect to the core code of slot function according to the signal name in , This line of code is used to put QObject Some of the signals of a neutron object follow its objextName Connect to the corresponding slot function summary ,
Secondly, the connection format is :
@QtCore.pyqtSlot()
def on_objectSignal_function(self):
objectName It's the name of the control
function The signal of the control to be connected , Here is the click signal clicked
One problem with whimsy is , If my objectName It's a Chinese name , So this one functionName Isn't it very awkward !!
ok , That's all , As for this method, how to produce parameters , It's the same feeling emit equally , About the same !
边栏推荐
- Flutter common commands and problems
- Some fields are ignored in tp6 query
- SQL function summary
- Online blind box system development function introduction and some source code sharing
- If you also want to be we media, you might as well listen to Da Zhou's advice
- Pycaret successfully resolved the problem that 'sklearn model_ selection._ Search 'import name "\u check\u param\u grid"
- Why should Apple change objc_ Type declaration for msgsend
- 2022 Baidu collection batch automatic push assistant
- ARM V7 ldr str 内存访问
- Découvrir gaussdb (pour redis): une comparaison complète avec Codis
猜你喜欢

Linear regression of common mathematical modeling models for College Students

一篇文章讲清楚MySQL的聚簇/联合/覆盖索引、回表、索引下推

Flutter common commands and problems

Understanding and construction of devsecops and Devops

K8s, docker compose install MySQL 8.0.18

ECSHOP quickly purchases goods, simplifies the shopping process, and improves the user experience through one-step shopping

刷入Magisk通用方法

How do super rookies get started with data analysis?

Dark horse shopping mall ---2 Distributed file storage fastdfs

15. Notes on the button style of WPF
随机推荐
Digital currency exchange -- digital currency exchange system development source code sharing
[data midrange] what is the oneid of the data midrange? Isn't the master data fragrant?
揭秘GaussDB(for Redis):全面对比Codis
Web project development process
Time series analysis - how to use unit root test (ADF) correctly?
The R language cartools package divides data, the scale function scales data, and the NaiveBayes function of e1071 package constructs a naive Bayesian model
laravel 9
High imitation blue playing network disk file sharing to make money network disk PHP system source code
Explain AHP in human language (very detailed principle + simple tool implementation)
R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the lrtest function of epidisplay package to perform multiple model
Execution order of MySQL query statements join, on and where
Laravel excel export
Figure explanation of fiborache sequence
[oceanbase] Introduction to oceanbase and its comparison with MySQL
Understanding and construction of devsecops and Devops
An example of using dynamic datalist
Wait for the end of the network request in the uniapp Onshow method before executing the subsequent code content
Laravel echart statistical chart line chart
An easy-to-use seal design tool - (can be converted to ofd file)
R language uses ordinal or. The display function obtains the summary statistical information of the ordered logistic regression model (the odds ratio and its confidence interval corresponding to the v