Getting a QlineEdit() to output text to a QTableWidget() Cell in PyQT4



  • I have 2 files...

    My init.py file...
    @
    class StartMain(QtGui.QMainWindow):
    def init(self, parent=None):
    QtGui.QWidget.init(self, parent)
    self.ui = Ui_MainWindow()
    self.ui.setupUi(self)

    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)
    
        if inputNumber > 1:
            #info = "Your User Code is %s" % inputNumber 
            tableWidget.item.setText("MainWindow", "%s"% inputNumber, None)
    

    if name == "main":

    Starts Main Window

    mainapp = QtGui.QApplication(sys.argv)
    mainappwin = StartMain()
    mainappwin.show()
    

    #User Box
    ucWindow = QtGui.QDialog()
    ucClass = StartUC()
    ucClass.show()
    sys.exit(mainapp.exec_())@



  • And thess Classes of my User Interface File PDIUI.py

    @
    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))
    

    #Main Interface Window
    def retranslateUi(self, MainWindow):
    MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
    self.tableWidget.setSortingEnabled(True)
    item = self.tableWidget.verticalHeaderItem(0)
    item.setText(_translate("MainWindow", "1", None))
    item = self.tableWidget.horizontalHeaderItem(0)
    item.setText(_translate("MainWindow", "DATE/TIME", None))
    item = self.tableWidget.horizontalHeaderItem(1)
    item.setText(_translate("MainWindow", "USER", None))
    item = self.tableWidget.horizontalHeaderItem(2)
    item.setText(_translate("MainWindow", "RECIPE#", None))
    item = self.tableWidget.horizontalHeaderItem(3)
    item.setText(_translate("MainWindow", "MATERIAL", None))
    item = self.tableWidget.horizontalHeaderItem(4)
    item.setText(_translate("MainWindow", "LOT#", None))
    item = self.tableWidget.horizontalHeaderItem(5)
    item.setText(_translate("MainWindow", "BATCH#", None))
    item = self.tableWidget.horizontalHeaderItem(6)
    item.setText(_translate("MainWindow", "TARE WT.", None))
    item = self.tableWidget.horizontalHeaderItem(7)
    item.setText(_translate("MainWindow", "PRODUCT WT.", None))
    __sortingEnabled = self.tableWidget.isSortingEnabled()
    self.tableWidget.setSortingEnabled(False)
    localtime = time.asctime( time.localtime(time.time()) )
    item = self.tableWidget.item(0, 0)
    item.setText(_translate("MainWindow", "%s" % localtime , None))
    item = self.tableWidget.item(0, 1)
    #item.setText(_translate("MainWindow", "" , None))
    self.tableWidget.setSortingEnabled(__sortingEnabled)
    self.label.setText(_translate("MainWindow", "Database version: %s " % vdata, None))
    self.pushButton.setText(_translate("MainWindow", "Add Weight", None))
    @



  • All I want to do it is get the QlineEdit box to output its text into one of the Cells of the QTableWidget Class object but for the life of me I can' figure it out... I have a QtCore.Signal returnPressed event method linked to and "if Statement" in my init.py which seems to work fine when I use it to output to command line but I can't figure out the proper syntax and methods to use to get it to output to:

    @
    item.setText(_translate("MainWindow", "" , None))
    @

    I'm using PyQt4 and Python2. Any help at all would be greatly appreciated.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.