Common software window size changes (maximized, manual changes) require the window components to be able to adapt to the layout, and in the QT application interface design, for beginners like me how to implement the window adaptive adjustment or a detour. Baidu on the Internet a lot, most of it is very vague, there are a lot of programs to achieve, since already have QT creator so high integration tools, I still tend to directly in the Qt creator through the visual configuration of the way to complete, one is WYSIWYG, but the efficiency is much higher.
In QT If you want to implement the window body space as the form resizes, you must use layout management, common layout management has qhboxlayout, qvboxlayout, qgridlayout, empty place use spacer control to fill.
I use qgridlayout here, CTRL + Select the form controls that need layout, right-layout-rasterize, adjust as needed.
The most important thing to do is to make the control adjust to the form by setting the size policy for the widgets, as shown in the controls. ‘
This part of the specific parameter explanation excerpt is as follows:
Combines the control's Sizepolicy property to control the size adaptation of controls in Layout management.
The Sizepolicy of the control describes how the control is scaled in layout management. The controls provided by QT have a reasonable default sizepolicy, but this default value sometimes does not fit all layouts, and developers often need to change the sizepolicy of some controls on the form. All variables of a qsizepolicy apply to both horizontal and vertical directions. Some of the longest values are listed below:
A. Fixed: The control cannot be enlarged or shrunk, and the size of the control is its sizehint.
B. Minimum: The sizehint of the control is the minimum size of the control. The control cannot be less than this sizehint, but can
Amplification.
C. Maximum: The sizehint of the control is the maximum size of the control, and the control cannot be enlarged, but it can be reduced to its minimum
The allowable size.
D. Preferred: The sizehint of the control is its sizehint, but can be scaled up or down
E. Expandint: Controls can grow or shrink themselves
Note: Sizehint (the default size for controls in layout management, if the control is not an invalid value in Layout management)
So for parts that need to change according to the size of the window, I'll set it to Expandint.
There are also settings for the scaling factor below the part size policy to set the corresponding proportions of the widget during the scaling process, which can be explored on its own.
To achieve this, it is important to set the top-level layout as the window automatically scales, and for a window to have only one layout as its top-level layout, and just the layout between the controls, so it needs to be laid out in the form layout.
Right-click where there is no control-layout-layout in the body layout, as shown in:
Qt Creator Form Control Adaptive Window size layout (RPM)