QtCore connectSlotsByName, 无其他connect函数,但是仍然每次被激活2次
#!/usr/bin/env python
# coding: utf-8
import sys
from PyQt5.QtWidgets import QApplication,QMainWindow,QWidget
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(432, 243)
self.gridLayoutWidget = QtWidgets.QWidget(Form)
self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 60, 411, 171))
self.pushButton = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton.setObjectName("pushButton")
self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
self.gridLayout.addWidget(self.pushButton, 4, 0, 1, 1)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
#self.pushButton.clicked.connect(MyForm.showit)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton.setText(_translate("Form", "Add Slots"))
class MyForm(QMainWindow,Ui_Form):
def __init__(self):
super(MyForm, self).__init__()
self.setupUi(self)
采用connectSlotsByName,用cliecked命名,如下就总是运行2次
#@QtCore.pyqtSignature("")
def on_pushButton_clicked(self):
print ("A")
@staticmethod
def showit(self):
print ("B")
app = QApplication(sys.argv)
a = MyForm()
a.show()
app.exec()
Maybe you can find answer here,
pyqt button automatically binds to on_…_clicked function without connect or pyqtSlot