[PyQt] Re: Modelss dialog not usable

duncan duncan duncan73 at gmail.com
Mon Dec 17 15:51:21 GMT 2007


On Dec 17, 2007 3:56 PM, Andreas Pakulat <apaku at gmx.de> wrote:

> On 17.12.07 15:08:23, duncan duncan wrote:
> > On Dec 17, 2007 3:00 PM, duncan duncan <duncan73 at gmail.com> wrote:
> >
> > > Hello.
> > >
> > > In my application (a QApplication), as central widget I have two
> > > QListWidget.
> > >
> > > When I double click on an item of a list widget, I want to show a
> dialog
> > > with some detail data for the item
> > >
> > >
> > > This is the relevant code, the dialog is designed using Qt-Designer
> and
> > > windowModality is Qt::NonModal
> > >
> > > ---
> > > ItemDlg = QtGui.QDialog()
> > > ItemDlgGui = Ui_D_item_detail()
> > > ItemDlgGui.setupUi(ItemDlg)
> > >
> > > ItemDlg.show()
> > >
> > > #ItemDlg.exec_()
> > > ---
> > >
> > > If I use the ItemDlg.exec_() line, all work correctly, but the dialog
> is
> > > modal, so I cannot work on the main window.
> > >
> > > Since I want a modeless dialog, I try to use ItemDlg.show() but now
> the
> > > dialog show itself and then close immediatly.
> > >
> > > Any hints ?
> > >
> >
> > It seems that by mistake I resolve the problem.
> >
> > It just need to call the .show() AND the .exec_() function.
>
> No you don't. You actually want to make sure the instance doesn't get
> deleted once the function that creates it ends. Thats why its closed
> immediately when you only use show(). When the function ends, there's no
> refernece to the dialog anymore, because ItemDlg is a local variable,
> thus the dialog is garbage collected.
>




>
> Do something like self.itemdialog = QtGui.QDialog() instead of the first
> line above.
>

Actually I modified all the structure, so these lines of codes are in the
__init__ function of a derived class (not important I suppose).

The whole point of the problem is that I want (and I need) to be able to
open the dialog (the display a set of editable data), look at it, modify
some field, then eventually open another dialog which display some diffente
data (basically the data are record of a db table)

If in the __init__ funciont I put the code you suggest, without the call to
.exec_(), the dialog close immediatly. I suppose that this happen because
self is not a pointer to the application, but a pointer to the dialog class.

For now it work as I expect, I will do further investigation as soon as the
code will stabilize a little (and all the feature are implemented)

Thanks anyway
bye
Gianluca
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20071217/cb7257aa/attachment-0001.html


More information about the PyQt mailing list