Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@vyx02237

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

More than 1 year has passed since last update.

備忘録かつ添削をお願いしたく。
.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クラスの意味と使い方もつかめたように思います。

0
Help us understand the problem. What is going on with this article?
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.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?