PDA

View Full Version : Resizing child widget



drmath
15th November 2010, 17:57
My project consists of a Main Window displaying a graphical custom widget. I'd like to fill main form with widget frame, and bind together their resizing. Until now I found:

1. Adding in MainWindow constructor the code

ui->MyCustomWidget->setGeometry(0,0,this->width(),this->height());

QBoxLayout *layout = new QBoxLayout(QBoxLayout::LeftToRight,this);
layout->addWidget(ui->MyCustomWidget);
this->setLayout(layout);

So doing child widget fills the parent window but do not resize according to parent resizing (do not change at all).

2. From designer, right clicking on main form and selecting layout/layout in a grid command. So doing, child resizing works fine but I get an unwanted void frame around the widget.

3. Subclassing MainWindow::resizeEvent. In such a case widget frame fills completely parent window and resizing works fine.

Do you know a way to achieve 1 or 2 issues?

MarekR22
15th November 2010, 19:57
Do solution nr 2 then select centralWidget, scroll widget properties to bottom to see layout properties then modify layouts margins as you wish.

drmath
16th November 2010, 10:12
Ok, it works. Any idea about nr 1 issue?

wysota
16th November 2010, 10:17
Any idea about nr 1 issue?
You need to set the layout on the central widget and not on the main window widget, it has its own layout.

drmath
16th November 2010, 11:32
Ok (if needed we have to add at bottom "layout->setContentsMargins(0,0,0,0);" code to remove void frame around central widget). Thanks