Help us understand the problem. What is going on with this article?

QtDesigner の作る .py でメインウインドウから ダイアログを呼び出して値を受けとるまで

備忘録かつ添削をお願いしたく。
.uiから pyside2-uic で生成される .py ファイル2つで、メインウインドウからダイアログを呼び出して値を受けとるまで。
setupUi利用の例として別な場面でも使えるのではと思います。

メインウインドウ側

main.py
#当該部分のみ
from dia import Ui_Dialog #ダイアログ側呼び込み

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):

#メイン側のsetupUiの中で、自身の持ち物としてQDialogを作り、ダイアログ側に渡してsetupUiしてもらう

        self.Dialog = QtWidgets.QDialog()
        sub = Ui_Dialog()
        sub.setupUi(self.Dialog)

#ダイアログ利用する場面で呼び出す
    def opendialog(self):
        result = self.Dialog.exec_()
        t = self.Dialog.findChild(QtWidgets.QLineEdit,"hogeLineEdit")
        print(result)
        print( t.text())

ダイアログ側

dia.py
#setGeometry関係カットしてあります

class Ui_Dialog(object):
    def setupUi(self, Dialog):

        Dialog.setObjectName("Dialog")

        self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)

        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.lineEdit = QtWidgets.QLineEdit(Dialog)
        self.lineEdit.setObjectName("hogeLineEdit")

        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), Dialog.accept)
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), Dialog.reject)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

なんだかUiクラスの意味と使い方もつかめたように思います。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした