简体   繁体   中英

How do I access the information from QLineEdit widget from another class?

PYQT5 ON PYCHARM

Currently, I have a MainWindow(mainwindow.py) class and a DialogWindow(dialog.py) class. Also, I have a main.py file which runs the code for both classes. I would like to set the text of the label in dialog.py to be the information from mainwindow.py, QLineEdit, inputedit. May I know how will I be able to do this? Appreciate any help provided. Thanks!

mainwindow.py

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        self.inputedit = QtWidgets.QLineEdit(self.centralwidget)
        self.inputedit.setGeometry(QtCore.QRect(80, 80, 311, 21))
        self.inputedit.setPlaceholderText("Input company name in ALL CAPITAL LETTERS")
        self.inputedit.setObjectName("inputedit")

dialog.py

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        self.label = QtWidgets.QLabel(Dialog)
        self.label.setGeometry(QtCore.QRect(30, 40, 351, 91))
        self.label.setObjectName("label")
    def retranslateUi(self, Dialog):
        self.label.setText(_translate("Dialog", "ASD"))

main.py

class MyDialog(QDialog):
    def __init__(self):
        super().__init__()
        self.ui  = Ui_Dialog()
        self.ui.setupUi(self)


class MyWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

    def dialogbox(self):
        self.hide()
        self.myDialog = MyDialog()
        self.myDialog.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = MyWindow()
    w.show()
    sys.exit(app.exec_())

The idea is to access both objects in a scope that share that in this case it is dialogbox, considering the above the solution is:

def dialogbox(self):
    self.hide()
    self.myDialog = MyDialog()
    
    self.myDialog.show()

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM