[PyQt] Qt4: Open a QDialog.

Andreas Pakulat apaku at gmx.de
Mon Mar 12 09:11:40 GMT 2007


On 12.03.07 09:44:48, Tina I wrote:
> I'm having some problems moving from Qt3 to Qt4. Kinda stuck in old habits I 
> guess.
> Anyway, my current problem is to simply open a dialog window I have made with 
> Designer but I can't for the life of me understand how to do it. In Qt3 it was 
> just a matter of importing the dialog and do something like "if 
> dialog.exec_loop() == QDialog.Accepted:". I have looked at the examples but I'm 
> none the wiser I'm afraid.

Its really easy:

dlg=QtGui.QDialog()
dlgui=Ui_Dialog()
dlgui.setupUi(dlg)
if( dlg.exec_() == ... ):
...

The Ui_Dialog class you created in designer only contains code that adds
the widgets to a given QDialog or QWidget parent. Its not a QDialog
subclass anymore. The approach above of course only works if you don't
need extra code to handle the dialog. If you do you'd create a subclass
from QDialog and do the same thing as with the mainwindow (self.ui =...
self.ui.setupUi(this)). This is documented in the Qt4 designer manual,
to be found on doc.trolltech.com/4.2

Andreas

-- 
You have an ability to sense and know higher truth.


More information about the PyQt mailing list