Where to set the main window size?

Hi everyone,
I create a new GUI application type project follow the “Tutorial: The main component”.
It seems that we could set the window size both in the MainComponent class’s constructor and in the MainWindow class’s constructor by the use of “setSize” function. When the “setSize” functionexists both in these two constructor function, the “setSize” function will not take effects in MainComponent class’s constructor function. What is the difference?

When you call setContentOwned() it will eventually end up here:

With resizeToFitWhenContentChangesSize default set to true.

So the child’s size is propagated to the window.

Setting in MainWindow a size afterwards will undo your call in the component’s constructor (by calling the window’s resized()).

1 Like

Thank you!
It seems that “setSize” function in the MainComponent class’s constructor is called first and then “setSize” function in the MainWindow class’s constructor. Is that right?
I am still confused with “resizeToFitWhenContentChangesSize” parameter of function “void ResizableWindow::setContentOwned()”.

If you set that to false, the window will keep its own size, regardless if the contained component changes its size. Most of the times you want the window to reflect the content’s size though.

In the startup sequence you posted it doesn’t matter though, since the window’s size is set afterwards, and that one is always propagated to the contained component.

1 Like