[PyQt] Re: dialogs and extentions

Mark Summerfield mark at qtrac.eu
Thu Oct 30 07:45:38 GMT 2008


On 2008-10-29, Wim Verhavert wrote:
> Thanks for your reply Mark. I tried the discussed procedure this
> afternoon, and yes this works, but as you said, this will not allow
> for user resize, which is a pitty. The older approach did allow for
> resize, so I consider this a step back. Do you see any reason why they
> want to remove this from the API?

I don't know why they made that change.
If you don't call setSizeConstraint() the dialog is resizable and is the
right size when you start and the right size when the extension is
shown. But when the extension is hidden again the dialog does not resize
down, so that's the only case you have to fix---but I don't think it is
easy to do!

> Thanks again, and by the way: your book is great!

Thanks:-D

> Wim
>
> On Wed, Oct 29, 2008 at 4:02 PM, Mark Summerfield <mark at qtrac.eu> wrote:
> > On 2008-10-29, Wim Verhavert wrote:
> >> I already found out that you can set the orientation with a call to
> >> 'setOrientation(Qt.Vertical)'. That solves my problem for now. But
> >> while I was searching for a solution I found the following:
> >> http://doc.trolltech.com/4.4/qdialog-obsolete.html. There they state
> >> that my solution is obsolete and "we strongly advise against using
> >> them in new code". But the new method they propose, i.e. simply hide
> >> or show the widgets, will not resize my dialog properly (it will only
> >> grow and not shrink). I played around with this for a while but
> >> couldn't get it to working. Has anybody done it using this new method.
> >> Does it shrink properly again? How do you do it?
> >
> > A technique for doing what you want is to:
> > (1) Put all the widgets that belong in the extension inside a QFrame
> >    that is itself laid out as usual
> > (2) In the form's __init__
> >    (a) hide the frame (thus hiding all the widgets it contains)
> >    (b) call: self.layout().setSizeConstraint(QLayout.SetFixedSize)
> >    (c) connect the button widget you're using to hide/show the
> >        extension's toggled(bool) signal to the frame's setVisible(bool)
> >        slot.
> >
> > Using this approach the dialog shrinks or grows as appropriate. The only
> > downside is that it is not user resizeable.
> >
> > An example is in my book "Rapid GUI Programming with Python and Qt", and
> > you can download the examples from here:
> > http://www.qtrac.eu/pyqtbook.html
> >
> > The example is:
> >    eg/chap09/findandreplace.{py,pyw}
> > (the .pyw version is all in code the .py version's form is a .ui file)
> >
> >
> > --
> > Mark Summerfield, Qtrac Ltd, www.qtrac.eu
> >    C++, Python, Qt, PyQt - training and consultancy
> >        "C++ GUI Programming with Qt 4" - ISBN 0132354160



-- 
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
    C++, Python, Qt, PyQt - training and consultancy
        "Rapid GUI Programming with Python and Qt" - ISBN 0132354187




More information about the PyQt mailing list