I wrote a gui with qt and converted it into python.it came below.
know I want to use the information witch user entered.for example the text boxes text or want decide around the buttons clicked or any thing else.at all how can i manage my qt forms data in my program?

from PyQt4 import QtCore, QtGui

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(324, 202)
        self.pushButton = QtGui.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(190, 160, 101, 23))
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtGui.QPushButton(Dialog)
        self.pushButton_2.setGeometry(QtCore.QRect(10, 160, 101, 23))
        self.pushButton_2.setObjectName("pushButton_2")
        self.textEdit = QtGui.QTextEdit(Dialog)
        self.textEdit.setGeometry(QtCore.QRect(210, 10, 104, 31))
        self.textEdit.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.textEdit.setTabChangesFocus(True)
        self.textEdit.setObjectName("textEdit")
        self.textEdit_2 = QtGui.QTextEdit(Dialog)
        self.textEdit_2.setGeometry(QtCore.QRect(210, 60, 104, 31))
        self.textEdit_2.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.textEdit_2.setTabChangesFocus(True)
        self.textEdit_2.setObjectName("textEdit_2")
        self.textEdit_3 = QtGui.QTextEdit(Dialog)
        self.textEdit_3.setGeometry(QtCore.QRect(10, 10, 104, 31))
        self.textEdit_3.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.textEdit_3.setTabChangesFocus(True)
        self.textEdit_3.setObjectName("textEdit_3")
        self.textEdit_4 = QtGui.QTextEdit(Dialog)
        self.textEdit_4.setGeometry(QtCore.QRect(10, 60, 104, 31))
        self.textEdit_4.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.textEdit_4.setTabChangesFocus(True)
        self.textEdit_4.setObjectName("textEdit_4")
        self.textEdit_5 = QtGui.QTextEdit(Dialog)
        self.textEdit_5.setGeometry(QtCore.QRect(110, 110, 104, 31))
        self.textEdit_5.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.textEdit_5.setTabChangesFocus(True)
        self.textEdit_5.setObjectName("textEdit_5")

        self.retranslateUi(Dialog)
        QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked(bool)"), Dialog.reject)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("Dialog", "پاك كردن", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_2.setText(QtGui.QApplication.translate("Dialog", "ثبت كردن", None, QtGui.QApplication.UnicodeUTF8))
        self.textEdit.setHtml(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"right\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">Test string</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.textEdit_2.setHtml(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"right\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\"></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.textEdit_3.setHtml(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"right\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\"></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.textEdit_4.setHtml(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"right\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\"></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.textEdit_5.setHtml(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"right\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\"></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    Dialog = QtGui.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())

I used qt designer for this code.

Recommended Answers

All 4 Replies

from PyQt4 import QtCore, QtGui

class Ui_frmMain(object):
    def setupUi(self, frmMain):
        frmMain.setObjectName("frmMain")
        frmMain.resize(254, 170)
        self.btnClear = QtGui.QPushButton(frmMain)
        self.btnClear.setGeometry(QtCore.QRect(90, 140, 75, 23))
        self.btnClear.setObjectName("btnClear")
        self.btnExit = QtGui.QPushButton(frmMain)
        self.btnExit.setGeometry(QtCore.QRect(170, 140, 75, 23))
        self.btnExit.setObjectName("btnExit")
        self.btnSave = QtGui.QPushButton(frmMain)
        self.btnSave.setGeometry(QtCore.QRect(10, 140, 75, 23))
        self.btnSave.setObjectName("btnSave")
        self.txtName = QtGui.QTextEdit(frmMain)
        self.txtName.setGeometry(QtCore.QRect(10, 10, 104, 21))
        self.txtName.setObjectName("txtName")
        self.txtFamily = QtGui.QTextEdit(frmMain)
        self.txtFamily.setGeometry(QtCore.QRect(10, 40, 104, 21))
        self.txtFamily.setObjectName("txtFamily")
        self.txtFather = QtGui.QTextEdit(frmMain)
        self.txtFather.setGeometry(QtCore.QRect(10, 70, 104, 21))
        self.txtFather.setObjectName("txtFather")
        self.txtStNum = QtGui.QTextEdit(frmMain)
        self.txtStNum.setGeometry(QtCore.QRect(10, 100, 104, 21))
        self.txtStNum.setObjectName("txtStNum")
        self.lblName = QtGui.QLabel(frmMain)
        self.lblName.setGeometry(QtCore.QRect(160, 10, 81, 16))
        self.lblName.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.lblName.setObjectName("lblName")
        self.lblFamily = QtGui.QLabel(frmMain)
        self.lblFamily.setGeometry(QtCore.QRect(160, 40, 81, 16))
        self.lblFamily.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.lblFamily.setObjectName("lblFamily")
        self.lblFather = QtGui.QLabel(frmMain)
        self.lblFather.setGeometry(QtCore.QRect(160, 70, 81, 16))
        self.lblFather.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.lblFather.setObjectName("lblFather")
        self.lblStNum = QtGui.QLabel(frmMain)
        self.lblStNum.setGeometry(QtCore.QRect(150, 100, 91, 16))
        self.lblStNum.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.lblStNum.setObjectName("lblStNum")

        self.retranslateUi(frmMain)
        QtCore.QObject.connect(self.btnClear, QtCore.SIGNAL("clicked()"), self.txtStNum.clear)
        QtCore.QObject.connect(self.btnClear, QtCore.SIGNAL("clicked()"), self.txtFamily.clear)
        QtCore.QObject.connect(self.btnClear, QtCore.SIGNAL("clicked()"), self.txtFather.clear)
        QtCore.QObject.connect(self.btnClear, QtCore.SIGNAL("clicked()"), self.txtName.clear)
        QtCore.QObject.connect(self.btnExit, QtCore.SIGNAL("clicked()"), frmMain.reject)
        QtCore.QMetaObject.connectSlotsByName(frmMain)

    def retranslateUi(self, frmMain):
        frmMain.setWindowTitle(QtGui.QApplication.translate("frmMain", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
        self.btnClear.setText(QtGui.QApplication.translate("frmMain", "Clear", None, QtGui.QApplication.UnicodeUTF8))
        self.btnExit.setText(QtGui.QApplication.translate("frmMain", "Exit", None, QtGui.QApplication.UnicodeUTF8))
        self.btnSave.setText(QtGui.QApplication.translate("frmMain", "Save", None, QtGui.QApplication.UnicodeUTF8))
        self.lblName.setText(QtGui.QApplication.translate("frmMain", "Name", None, QtGui.QApplication.UnicodeUTF8))
        self.lblFamily.setText(QtGui.QApplication.translate("frmMain", "Family", None, QtGui.QApplication.UnicodeUTF8))
        self.lblFather.setText(QtGui.QApplication.translate("frmMain", "Father Name", None, QtGui.QApplication.UnicodeUTF8))
        self.lblStNum.setText(QtGui.QApplication.translate("frmMain", "Students Code", None, QtGui.QApplication.UnicodeUTF8))


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    frmMain = QtGui.QDialog()
    ui = Ui_frmMain()
    ui.setupUi(frmMain)
    frmMain.show()
    sys.exit(app.exec_())

if my code be such. now

QtCore.QObject.connect(self.btnSave, QtCore.SIGNAL("clicked()"), self.setValue)

clicked is my event and my signal.and it will be call the setValue() function witch is my slot.

def setValue(self):
    name = txtName.؟؟؟؟؟

now I have problem for accessing the txtNames value.
how do you solve this.

and another question.The way that I did is a usual way.
Its my first time that am runing such program.before I dont worked with guies.when a programer wants do such program, how does he play?

This is an example I had using QLineEdit and QTextEdit. There are other ways to retrieve text based on starting and ending positions but I don't use it.

import sys
from PyQt4 import QtGui, QtCore

class GridLayout2(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.setWindowTitle('grid layout')

        title = QtGui.QLabel('Title')
        author = QtGui.QLabel('Author')

        self.title_edit = QtGui.QLineEdit()
        self.author_edit = QtGui.QTextEdit()

        grid = QtGui.QGridLayout()
        grid.setSpacing(10)

        grid.addWidget(title, 1, 0)
        grid.addWidget(self.title_edit, 1, 1)

        grid.addWidget(author, 2, 0)
        grid.addWidget(self.author_edit, 2, 1)

        c_button = QtGui.QPushButton("Continue")
        grid.addWidget(c_button, 3, 0)
        self.connect(c_button, QtCore.SIGNAL("clicked()"), \
                     self.button_click)

        quit_button = QtGui.QPushButton("Exit")
        grid.addWidget(quit_button, 3, 1)
        self.connect(quit_button, QtCore.SIGNAL("clicked()"), \
                     self.exit_widget)

        self.setLayout(grid)
        self.resize(250, 150)


    def button_click(self):
        print "button click called"
        print "self.title_edit", self.title_edit.text()
        print "\nself.author_edit"
        print self.author_edit.document().toPlainText()


    def exit_widget(self):
        self.button_click()
        self.close()

app = QtGui.QApplication(sys.argv)
qb = GridLayout2()
qb.show()
sys.exit(app.exec_())

Thanks.
Sorry can we do it with LineEdit, Text Edit or Plane Text Edit?
and it if maybe introduce me a refrence of them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.