[Qt-interest] showing designed widgets in a layout

Tony Rietwyk tony.rietwyk at rightsoft.com.au
Tue Apr 13 14:39:01 CEST 2010


> -----Original Message-----
> hi all,
> I have a widget class in which I try to put some widgets in a layout.
> First widget is a QLabel.
> The other widgets are widgets designed by Qt Designer 
> (widgets have .ui files).
> In constructor of parent widget class, which will show all these
> widgets, the code is like this:
> 
> Widget1 *designedWidget1 = new Widget1();
> Widget2 *designedWidget2 = new Widget2 ();
> Widget3 * designedWidget3 = new Widget3 ();
> QLabel *myLabel= new QLabel();
> myLabel->setPixmap(QPixmap::fromImage(QImage("inputImage.jpg")));
> 
> QVBoxLayout *vl = new QVBoxLayout(this);
> vl->addWidget(myLabel);
> vl->addWidget(designedWidget1 );
> vl->addWidget(designedWidget2 );
> vl->addWidget(designedWidget3 );
> setLayout(vl);
> 
> After this code sequence parent widget only show the QLabel widget,
> other designed widgets are invisible.
> Am I doing a wrong thing, is it impossible to show designed 
> widgets in a layout?

Hi Mehmet, 

You may need to change the size policies on the designed widgets. 

Do the designed widgets have their own (sub) layout?  If not, then you also
need to ensure they return a valid sizeHint, or are constrained by the
minimum/maximum sizes.  

You may be able to use the 'promote' feature in designer to design the form
that you are now building in code.  Simply add the base class of each
designed widget into the form with the label and layout.  Then promote the
base classes to Widget1, 2 and 3.  

Hope that helps, 

Tony




More information about the Qt-interest-old mailing list