I'm new to both Python and PyQT4.
I have this simple QDialog Box with a QlineEdit in it.
class Ui_UserCode(object):
def setupUi(self, UserCode):
UserCode.setObjectName(_fromUtf8("UserCode"))
UserCode.resize(265, 125)
UserCode.setMouseTracking(False)
self.lineEdit = QtGui.QLineEdit(UserCode)
self.lineEdit.setGeometry(QtCore.QRect(60, 50, 151, 31))
self.lineEdit.setFrame(True)
self.lineEdit.setAlignment(QtCore.Qt.AlignCenter)
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
QtCore.QObject.connect(self.lineEdit, QtCore.SIGNAL(_fromUtf8("returnPressed()")), UserCode.insertUC)
self.label = QtGui.QLabel(UserCode)
self.label.setGeometry(QtCore.QRect(60, 20, 151, 20))
self.label.setObjectName(_fromUtf8("label"))
self.buttonBox = QtGui.QDialogButtonBox(UserCode)
self.buttonBox.setGeometry(QtCore.QRect(40, 90, 180, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.retranslateUi(UserCode)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), UserCode.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), UserCode.reject)
QtCore.QMetaObject.connectSlotsByName(UserCode)
def retranslateUi(self, UserCode):
UserCode.setWindowTitle(_translate("UserCode", "Dialog", None))
self.label.setText(_translate("UserCode", "Please Enter User Code", None))
self.lineEdit.setText(_translate("Dialog", "", None))
And this line of code in a separate Class for a QtableWidget I have created.
item.setText(_translate("MainWindow", "" , None))
And then... my init Classes and pyqtSlot()
class StartUC(QDialog):
def __init__(self):
QDialog.__init__(self)
self.uc = Ui_UserCode()
self.uc.setupUi(self)
self.ui = Ui_MainWindow()
@QtCore.pyqtSlot()
def insertUC(self):
inputNumber = self.uc.lineEdit.text()
tableWidget = StartMain(QTableWidgetItem)
item = tableWidget.item(0, 1)
tableWidget.item.setText("MainWindow", "%s"% inputNumber, None)
class StartMain(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
My Questions are how do I get the QlineEdit of the dialog box to populate the QtableWidgetCell on a returnPressed event? Is my pyqtSlot() method even in the right place? I realize I've still got lots to learn so if someone could point in the right direction that would be awesome. The PyQT documentation gave me a decent start but I'm not sure how to finish this...
Take a look at code that I wrote for this question https://stackoverflow.com/a/18447504/1155106
You can run it, it does some simple things so you can see how to use slots and signals and pass signal from class to class.
I hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.