PDA

View Full Version : QMainWindow size policy



Caius Aérobus
12th March 2011, 16:58
How it works?
I create a simple Widget, apply setFixedSize to that widget and put it as the central widget of a MainWindow and... the widget size is changed to 480x480!
I can't understand how it works and how I could make something as simple as asking the main window to just size itself so as to contain the child widget!
Sizing is soooooo complicated in Qt!

qlands
14th March 2011, 09:22
Hi,

If you use central widget, the window take ownership of the widget, meaning that the widget will fit the whole size of the window. If you want to resize your widget so resize the window with setGeometry(). If you want a widget that fits almost the whole area of your widget use layouts.

Sizing is not complicated in QT. Its very easy, it just follows a different philosophy.

wysota
14th March 2011, 09:34
How it works?
Size policy only works when a widget is inside a layout. Since your main window is a window, it is not inside any layouts so its size policy is ignored.


I can't understand how it works and how I could make something as simple as asking the main window to just size itself so as to contain the child widget!
Set a size constraint on the layout managing the widget you wish to control the size of its parent.

mainWindow()->layout()->setSizeConstraint(QLayout::SetFixedSize);