Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, November 2006
how to get minimumSize() before show()?


Message 1 in thread

Hi there

I have a form which I designed with designer. I do something along the lines 
of the following to instantiate it:

class MyFormWidget: public QWidget, Ui_MyForm { // Ui_MyForm  is the class 
output from uic
public:
 MyFormWidget( QWidget *parent )
  : QWidget( parent, contraptionView )
 {
  setupUi( this );
 }
};

...

MyFormWidget *myForm = new MyFormWidget(parent);

myForm->minimumSize(); // <---- this is (0,0) even though it shouldn't be

parent->setMinimumSize( myForm->minimumSize() + QSize( 5, 5 ) );
parent->resize( parent->minimumSize() );
parent->show();

---

The problem is that minimumSize doesn't seem to be valid just after I 
construct the widget. Does anyone know if this is expected behavior, and how 
to work around it? I need to resize parent according to the size constraints 
of the newly created widget (MyFormWidget in the above example)

Thanks!

Ross.

--
 [ signature omitted ] 

Message 2 in thread

Use QTimer::singleShot (0, this, SLOT(asSoonAsInitialized())) from within 
your mainform and the slot will be triggered right after the form has been 
layouted and the eventloop is entered the first time.

Regards,
Malte



"Ross Bencina" <rossb-lists@xxxxxxxxxxxxxx> schrieb am 02.11.2006 
08:19:53:

> Hi there
> 
> I have a form which I designed with designer. I do something along the 
lines 
> of the following to instantiate it:
> 
> class MyFormWidget: public QWidget, Ui_MyForm { // Ui_MyForm  is the 
class 
> output from uic
> public:
>  MyFormWidget( QWidget *parent )
>   : QWidget( parent, contraptionView )
>  {
>   setupUi( this );
>  }
> };
> 
> ...
> 
> MyFormWidget *myForm = new MyFormWidget(parent);
> 
> myForm->minimumSize(); // <---- this is (0,0) even though it shouldn't 
be
> 
> parent->setMinimumSize( myForm->minimumSize() + QSize( 5, 5 ) );
> parent->resize( parent->minimumSize() );
> parent->show();
> 
> ---
> 
> The problem is that minimumSize doesn't seem to be valid just after I 
> construct the widget. Does anyone know if this is expected behavior, and 
how 
> to work around it? I need to resize parent according to the size 
constraints 
> of the newly created widget (MyFormWidget in the above example)
> 
> Thanks!
> 
> Ross.
> 
> --
> 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx 
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 

--
 [ signature omitted ] 

Message 3 in thread

Hi Ross,

I am not sure, if this is guaranteed and will ever be, but it will 
definitely be called extremely early. I am pretty sure you will not see 
any flicker or something if you resize there.

I believe the eventqueue is organized pretty much like a fifo (correct me 
if I am wrong). So since you construct your widget before calling show(), 
which generates the paint-events, you will have the timer-event be 
processed before the painting stuff.

Regards,
Malte



"Ross Bencina" <rossb-lists@xxxxxxxxxxxxxx> schrieb am 02.11.2006 
09:09:22:

> Thanks Malte
> 
> But I'm not sure that solves my problem -- will the timer be called 
before 
> the widget is painted for the first time?
> 
> 
> > Use QTimer::singleShot (0, this, SLOT(asSoonAsInitialized())) from 
within
> > your mainform and the slot will be triggered right after the form has 
been
> > layouted and the eventloop is entered the first time.
> 
> Bests
> 
> Ross.
> 
> > "Ross Bencina" <rossb-lists@xxxxxxxxxxxxxx> schrieb am 02.11.2006
> > 08:19:53:
> >
> >> Hi there
> >>
> >> I have a form which I designed with designer. I do something along 
the
> > lines
> >> of the following to instantiate it:
> >>
> >> class MyFormWidget: public QWidget, Ui_MyForm { // Ui_MyForm  is the
> > class
> >> output from uic
> >> public:
> >>  MyFormWidget( QWidget *parent )
> >>   : QWidget( parent, contraptionView )
> >>  {
> >>   setupUi( this );
> >>  }
> >> };
> >>
> >> ...
> >>
> >> MyFormWidget *myForm = new MyFormWidget(parent);
> >>
> >> myForm->minimumSize(); // <---- this is (0,0) even though it 
shouldn't
> > be
> >>
> >> parent->setMinimumSize( myForm->minimumSize() + QSize( 5, 5 ) );
> >> parent->resize( parent->minimumSize() );
> >> parent->show();
> >>
> >> ---
> >>
> >> The problem is that minimumSize doesn't seem to be valid just after I
> >> construct the widget. Does anyone know if this is expected behavior, 
and
> > how
> >> to work around it? I need to resize parent according to the size
> > constraints
> >> of the newly created widget (MyFormWidget in the above example)
> >>
> >> Thanks!
> >>
> >> Ross.
> >>
> >> --
> >>
> >> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
> >> with "unsubscribe" in the subject or the body.
> >> List archive and information: http://lists.trolltech.com/qt-interest/
> >>
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 

> > "unsubscribe" in the subject or the body.
> > List archive and information: http://lists.trolltech.com/qt-interest/
> > 

--
 [ signature omitted ] 

Message 4 in thread

On Thu, 2 Nov 2006 18:19:53 +1100, "Ross Bencina"
<rossb-lists@xxxxxxxxxxxxxx> wrote:

>Hi there
>parent->setMinimumSize( myForm->minimumSize() + QSize( 5, 5 ) );


Try using minimumSizeHint();  

  parent->setMinimumSize( myForm->minimumSizeHint() + QSize( 5, 5 ));




--
 [ signature omitted ] 

Message 5 in thread

On Thursday 02 November 2006 10:18, Timpie.w@xxxxxxxxx wrote:
> On Thu, 2 Nov 2006 18:19:53 +1100, "Ross Bencina"
>
> <rossb-lists@xxxxxxxxxxxxxx> wrote:
> >Hi there
> >parent->setMinimumSize( myForm->minimumSize() + QSize( 5, 5 ) );
>
> Try using minimumSizeHint();
>
>   parent->setMinimumSize( myForm->minimumSizeHint() + QSize( 5, 5 ));

And there is showEvent (QShowEvent *) which is called before show ().

Frank

--
 [ signature omitted ]