[Qt-interest] Child Inherit Size of Parent

Sean Harmer sean.harmer at maps-technology.com
Sun Oct 31 15:42:28 CET 2010


Hi,

On Sunday 31 October 2010 14:24:57 velociraptor Genjix wrote:
> If I parent one widget to another widget, how can I get it to inherit it's
> parent's size?

Put the child in a layout in the parent. For e.g.

MyParent::MyParent( QWidget* parent = 0 )
 : QWidget( parent )
{
    MyChild* child = new MyChild( this );
    QVBoxLayout* layout = new QVBoxLayout;
    layout->addWidget( child );
    setLayout( layout );
}

The layout will automatically resize your child when the parent is resized. 
Take a look at the examples and docs relating to the Qt Layout System.

HTH,

Sean



More information about the Qt-interest-old mailing list