0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python2.7+PyQt4でメインウィンドウからダイアログボックスを表示させる メモ

Posted at

メインウィンドウからダイアログボックスを表示させる

メインウィンドウもダイアログボックスも最初にクラス宣言する。

# !/usr/bin/python
# -*- coding: utf-8 -*-

from PyQt4 import QtGui
from PyQt4 import QtCore
import sys

import mainwindow_ui #QtDesignで作成したメインウィンドウ ボタンを1個配置
import dialogbox_ui #QtDesignで作成したダイアログボックス

class DialogBox(QtGui.QDialog, dialogbox_ui.Ui_Dialog):
    def __init__(self):
        super(self.__class__, self).__init__()
        self.setupUi(self)
    
class MainWindow(QtGui.QMainWindow, mainwindow_ui.Ui_MainWindow):
    def __init__(self):
        super(self.__class__, self).__init__()
        self.setupUi(self)
        self.pushButton.clicked.connect(lambda: self.pushButtonAction())

    def pushButtonAction(self): #ボタンをクリックするとダイアログボックスが表示する
        self.dia = DialogBox()
        self.dia.exec_()
        


def main():
    app = QtGui.QApplication(sys.argv)
    form = MainWindow()
    form.show()
    app.exec_()



if __name__ == '__main__':
    main()           
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?