我想在 actionTracar Qaction 元素上发出触发信号,但它不起作用或给出任何错误。
我已经制作了一小段代码来解决它。但我还是想不通。
麻烦.py:
# -*- coding: utf-8 -*-
import sys
from PyQt4.QtCore import SIGNAL
from PyQt4.QtGui import QApplication, QMainWindow, QDoubleValidator
from Tela import Ui_MainWindow
class JanelaPolinomio (QMainWindow, Ui_MainWindow):
def __init__(self):
super(JanelaPolinomio, self).__init__()
self.setupUi(self)
self.actionTracar.emit(SIGNAL("triggered()"))
def on_actionTracar_triggered(self):
print "test"
if __name__ == '__main__':
app = QApplication(sys.argv)
jan = JanelaPolinomio()
jan.show()
sys.exit(app.exec_())
Tela.py:
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(390, 244)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 390, 21))
self.menubar.setObjectName(_fromUtf8("menubar"))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.toolBar = QtGui.QToolBar(MainWindow)
self.toolBar.setObjectName(_fromUtf8("toolBar"))
MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
self.actionTracar = QtGui.QAction(MainWindow)
self.actionTracar.setObjectName(_fromUtf8("actionTracar"))
self.toolBar.addAction(self.actionTracar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar", None))
self.actionTracar.setText(_translate("MainWindow", "tracar", None))
self.actionTracar.setShortcut(_translate("MainWindow", "Ctrl+T", None))
任何帮助表示赞赏。