Solved Understanding Widget sizing
-
I'm learning Qt and try to understand how widget sizing is working.
I have made a simple layout including a Gaphics view and a Button as shown below:
Both widgets are placed in a vertical layout and the sizes in the Designer are as follows:
So w=576 and h=393 for the Graphics view and w=576 and h=28 for the button.
For testing I have added the following code to the constructor:
My first question is why is sizeHint written in italics and size in normal?
Running the program provides the following outputs:
Graphics view size: QSize(100, 30)
Button size: QSize(100, 30)
Graphics view size hint: QSize(256, 192)
Button size hint: QSize(93, 28)None of these numbers are matching with the numbers in the designer, why? Where are these numbers comming from?
Then, I have reimplemented the resizeEvent function and copied the qDebug lines in it.
Now the outputs are as follows:
Now the sizes match with those from the Designer but why the sizehint of the Graphics view has changed and the size hint of the button has not?
When changing the size of the window with the mouse the minimum size is limited to the following numbers.
Again, where are these numbers comming from and why is the window limited to this size?
Is there a place in the documentation where these behaviors are described in depth?
-
Hi,
This link may help:
https://myprogrammingnotes.com/size-qt-widgets-determined.html -
@Bert59
To answer just why the numbers are not what you expect in the constructor. In a word, sizes only mean anything after a widget is actually shown. That's why, for example, they are correct inresizeEvent()
. Before.show()
they seem to be almost anything, don't rely on them. -
Hi,
This link may help:
https://myprogrammingnotes.com/size-qt-widgets-determined.html