[PyQt] How do you close a QDialog?

Demetrius Cassidy dcassidy36 at mass.rr.com
Wed Apr 8 06:04:54 BST 2009


> if __name__ == "__main__":
>     import sys
>     app = QtGui.QApplication(sys.argv)
>     Dialog = QtGui.QDialog() <-- don't do this
>     ui = action_select_dialog()
>     ui.setupUi(Dialog) <-- this should be inside __init__
>     Dialog.show() <-- this should have been ui.show() instead.
>     sys.exit(app.exec_())
> 

Heres the fixed code:

from PyQt4 import QtCore, QtGui

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(314, 50)
        Dialog.setMaximumSize(QtCore.QSize(314, 50))
        self.horizontalLayout = QtGui.QHBoxLayout(Dialog)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.pushButton = QtGui.QPushButton(Dialog)
        self.pushButton.setObjectName("pushButton")
        self.horizontalLayout.addWidget(self.pushButton)

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog",
"Octane", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("Dialog",
"Close", None, QtGui.QApplication.UnicodeUTF8))


class action_select_dialog(QtGui.QDialog, Ui_Dialog):
    def __init__(self):
        QtGui.QDialog.__init__(self)
        self.setupUi(self)
        self.connect(self.pushButton, QtCore.SIGNAL('clicked()'), self.o)
        

    def o(self):
        print "close the window"
        self.close()


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    ui = action_select_dialog()
    ui.show()
    sys.exit(app.exec_())

GatorAlli wrote:
> 
> from PyQt4 import QtCore, QtGui
> class action_select_dialog(QtGui.QDialog):
>     def setupUi(self, Dialog):
>         Dialog.setObjectName("Dialog")
>         self.pushButton_3 = QtGui.QPushButton(Dialog)
>         self.pushButton_3.setObjectName("pushButton_3")
>         QtCore.QObject.connect(self.pushButton_3,
> QtCore.SIGNAL("clicked()"), self.o)
>         QtCore.QMetaObject.connectSlotsByName(Dialog)
> 
>     def retranslateUi(self, Dialog):
>         Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog",
> "Octane", None, QtGui.QApplication.UnicodeUTF8))
>         self.pushButton_3.setText(QtGui.QApplication.translate("Dialog",
> "Add", None, QtGui.QApplication.UnicodeUTF8))
>     def o(self):
>         print "close the window"
>         self.close #<--------------------------------------------- CLOSE
> HERE
> 
> if __name__ == "__main__":
>     import sys
>     app = QtGui.QApplication(sys.argv)
>     Dialog = QtGui.QDialog()
>     ui = action_select_dialog()
>     ui.setupUi(Dialog)
>     Dialog.show()
>     sys.exit(app.exec_())
> 
> 
> 
Quoted from: 
http://www.nabble.com/How-do-you-close-a-QDialog--tp22874235p22941842.html


GatorAlli wrote:
> 
> from PyQt4 import QtCore, QtGui
> class action_select_dialog(QtGui.QDialog):
>     def setupUi(self, Dialog):
>         Dialog.setObjectName("Dialog")
>         self.pushButton_3 = QtGui.QPushButton(Dialog)
>         self.pushButton_3.setObjectName("pushButton_3")
>         QtCore.QObject.connect(self.pushButton_3,
> QtCore.SIGNAL("clicked()"), self.o)
>         QtCore.QMetaObject.connectSlotsByName(Dialog)
> 
>     def retranslateUi(self, Dialog):
>         Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog",
> "Octane", None, QtGui.QApplication.UnicodeUTF8))
>         self.pushButton_3.setText(QtGui.QApplication.translate("Dialog",
> "Add", None, QtGui.QApplication.UnicodeUTF8))
>     def o(self):
>         print "close the window"
>         self.close #<--------------------------------------------- CLOSE
> HERE
> 
> if __name__ == "__main__":
>     import sys
>     app = QtGui.QApplication(sys.argv)
>     Dialog = QtGui.QDialog()
>     ui = action_select_dialog()
>     ui.setupUi(Dialog)
>     Dialog.show()
>     sys.exit(app.exec_())
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-do-you-close-a-QDialog--tp22874235p22943181.html
Sent from the PyQt mailing list archive at Nabble.com.



More information about the PyQt mailing list