PYCHARM上的PYQT5
当前,我有一个MainWindow(mainwindow.py)类和一个DialogWindow(dialog.py)类。另外,我有一个main.py文件,它为两个类运行代码。我想将dialog.py中标签的文本设置为来自mainwindow.py,QLineEdit,inputedit的信息。我可以知道怎么做吗?感谢提供的任何帮助。谢谢!
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_())
答案 0 :(得分:0)
考虑到以上解决方案,该想法是访问在一个共享对话框的范围内的两个对象,在这种情况下,它是对话框。
def dialogbox(self):
self.hide()
self.myDialog = MyDialog()
self.myDialog.ui.label.setText(self.ui.inputedit.text())
self.myDialog.show()