当前位置:网站首页>(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 !
边栏推荐
- ARM 立即数
- 19. Implementation of MVVM architecture based on WPF event to command
- If you also want to be we media, you might as well listen to Da Zhou's advice
- Mpai data science platform SVM support vector machine classification \ explanation of regression parameter adjustment
- Zunpin Yongyao advertising e-commerce system -- Zunpin Yongyao advertising e-commerce app system development source code sharing
- 2022 meisai topic C idea sharing + translation
- Penetration tool environment - installing sqli labs in centos7 environment
- ECSHOP commodity wholesale multi attribute multi specification multi inventory batch purchase ECSHOP wholesale plug-in ECSHOP multi attribute order
- laravel 9
- Controllable character image synthesis based on attribute decomposition and Gan reproduction
猜你喜欢

Découvrir gaussdb (pour redis): une comparaison complète avec Codis
![[regression analysis] understand ridge regression with case teaching](/img/95/91f6f2a018b8d320945b12562492eb.jpg)
[regression analysis] understand ridge regression with case teaching

How to use SPSS to do grey correlation analysis? Quick grasp of hand-to-hand Teaching

The first techo day Tencent technology open day in 2022 will be held online on June 28

Zhangxiaobai's road to penetration (7) -sql injection detailed operation steps -union joint query injection

ECSHOP video list_ ECSHOP uploading video, video classification, video list playing video function

How do super rookies get started with data analysis?

Full nanny tutorial of Market Research Competition (experience sharing)

An easy-to-use seal design tool - (can be converted to ofd file)

What is the primordial universe
随机推荐
Laravel echart statistical chart line chart
R language dplyr package filter function filters the data rows in the specified list whose contents in the dataframe data are not (not equal to one of the specified vectors)
The first techo day Tencent technology open day in 2022 will be held online on June 28
MySQL and excel tables importing database data (Excel for MySQL)
ECSHOP whole site custom URL supports directory type
Heyangdao store management system -- share the development source code of heyangdao system
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
Mind mapping video
What is Flink? What can Flink do?
ARM V7 协处理器
MySQL common interview questions
Today, I will explain to you what is DFI and its development prospects
PHP numeric array sorting and associative array sorting
PHP appends the same elements to a two-dimensional array
sudo: ulimit: command not found
PHP takes the difference set of two arrays
The network traceroute command is used to determine the path through which IP packets access the destination address.
JS array length is defined
Yunfan mall -- Yunfan mall system development source code sharing
Arm V7 coprocessor