当前位置:网站首页>QT using layout manager is invalid or abnormal

QT using layout manager is invalid or abnormal

2022-06-13 04:54:00 qq_ thirty-nine million two hundred and eighty thousand seven h

1. Using the layout manager fails


Inherit and mainwindow Or... Again mainwindow The window of , Using layout manager will not work .
mainwindow Windows have their own layout management methods ,mainwindow There is a central part in the .
If you want to in mainwindow Use layout in , Sure new One widget parts , Then use the layout manager on the part ; Finally, set this component as the central component .

2. After using the layout manager , Cannot set the size of the part in it (setGeometry invalid ).


After using the layout manager , The size of the part position will be controlled by the layout manager . If you want to specify the size of the part , have access to setFixedsize function .
 

void QWidget::setFixedSize(const QSize &s)
Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing or shrinking.
This will override the default size constraints set by QLayout

/*
 Set the maximum size of the part , Minimum dimensions are s, Used to prevent stretching and expansion .
 This operation will override the default limit of the layout manager .
*/

3. Setting the layout management location size property is invalid (layout setGeometry)

The location attribute of the layout manager is inherited from the size of the parent part ( in the light of :QBoxLayout/QGridLayout).

QBoxLayout/QGridLayout  website :
takes the space it gets (from its parent layout or from the parentWidget())
/*  The size of the part comes from the parent part , Or father layout */

Since the size of the layout manager is determined by the size of the parent part space , Then we can start with new One part , Then set the position and size of the part , Finally, add a layout manager to the part .

4. After adding various parts to the layout manager , For example, horizontal layout manager , Abnormal size and position of parts .

Layout manager contains “margin” The edge of .

qt website :

void QLayout::setContentsMargins(int left, int top, int right, int bottom)
Sets the left, top, right, and bottom margins to use around the layout.
By default, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.
This function was introduced in  Qt 4.3

/*
 Set the top, bottom, left and right margins ,qt The default is 11px
*/

You can use the following functions , Change the margins .

setMargin() function ( The official advice is not to use , Exists for compatibility with older versions )
setContensMargin()

 

原网站

版权声明
本文为[qq_ thirty-nine million two hundred and eighty thousand seven h]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280518242120.html