当前位置:网站首页>QT learning 23 layout manager (II)
QT learning 23 layout manager (II)
2022-07-03 13:58:00 【A little black sauce】
Qt Study 23 Layout manager ( Two )
Layout manager
- In layout manager ratio
- By default, in an equal proportion Update the size of the component
- You can customize Component size update ratio
- QBoxLayout Scale factor setting in
- void setStretch(int index, int stretch)
- bool setStretchFactor(QWidget* widget, int stretch)
- bool setStretchFactor(QLayout* layout, int stretch)
Programming experiment - A preliminary study of the proportional coefficient
Add the function of setting the scale factor to the code in the previous section
void Widget::testVBoxLayout()
{
// Add window controls to layout manager
// Layout manager sets the spacing between controls
// Set the scale factor
layout->setStretch(0, 1);
layout->setStretch(1, 2);
layout->setStretch(2, 3);
layout->setStretch(3, 4);
// Set the layout manager of the current window
}
void Widget::testHBoxLayout()
{
// Add window controls to layout manager
// Layout manager sets the spacing between controls
// Set the scale factor
layout->setStretchFactor(&TestBtn1, 1);
layout->setStretchFactor(&TestBtn2, 3);
layout->setStretchFactor(&TestBtn3, 1);
layout->setStretchFactor(&TestBtn4, 4);
// Set the layout manager of the current window
}
void Widget::testVHBoxLayout()
{
// ...
vLayout->setStretchFactor(hLayout1, 1);
vLayout->setStretchFactor(hLayout2, 2);
// ...
}
- The initial size of the component is Independent of layout manager Set up , therefore There is no guarantee that the size of the component always conforms to the setting of the scale factor
QGridLayout Layout manager
- With grid ( A two-dimensional ) Manage interface components in a way

- QGridLayout Scale factor setting in
- void setColumnStretch(int column, int stretch)
- void setRowStretch(int row, int stretch)
Programming experiment - QGridLayout
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QPushButton>
class Widget : public QWidget
{
Q_OBJECT
private:
QPushButton TestBtn1;
QPushButton TestBtn2;
QPushButton TestBtn3;
QPushButton TestBtn4;
void initBtn();
void testGridLayout1();
void testGridLayout2();
public:
Widget(QWidget *parent = 0);
~Widget();
};
#endif // WIDGET_H
#include "Widget.h"
#include <QGridLayout>
Widget::Widget(QWidget *parent) : QWidget(parent),
TestBtn1(this), TestBtn2(this), TestBtn3(this), TestBtn4(this)
{
initBtn();
// testGridLayout1();
testGridLayout2();
}
Widget::~Widget()
{
}
void Widget::initBtn()
{
TestBtn1.setText("Test Button 1");
TestBtn1.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
TestBtn1.setMinimumSize(160, 30);
TestBtn2.setText("Test Button 2");
TestBtn2.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
TestBtn2.setMinimumSize(160, 30);
TestBtn3.setText("Test Button 3");
TestBtn3.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
TestBtn3.setMinimumSize(160, 30);
TestBtn4.setText("Test Button 4");
TestBtn4.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
TestBtn4.setMinimumSize(160, 30);
}
void Widget::testGridLayout1()
{
QGridLayout* layout = new QGridLayout();
layout->setSpacing(10);
// Grid layout management add button components
layout->addWidget(&TestBtn1, 0, 0);
layout->addWidget(&TestBtn2, 0, 1);
layout->addWidget(&TestBtn3, 1, 0);
layout->addWidget(&TestBtn4, 1, 1);
// Set row scale factor
layout->setRowStretch(0, 1);
layout->setRowStretch(1, 2);
// Set the column scale factor
layout->setColumnStretch(0, 3);
layout->setColumnStretch(1, 4);
setLayout(layout);
}
void Widget::testGridLayout2()
{
QGridLayout* layout = new QGridLayout();
layout->setSpacing(10);
// Grid layout management add button components across grids
layout->addWidget(&TestBtn1, 0, 0, 2, 1);
layout->addWidget(&TestBtn2, 0, 1, 2, 1);
layout->addWidget(&TestBtn3, 2, 0, 1, 2);
layout->addWidget(&TestBtn4, 3, 0, 1, 2);
setLayout(layout);
}
#include "Widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
- Nesting of layout managers
- QGridLayout Support Nest other layout managers Become its management object

Summary
- QGridLayout With Grid mode Manage components
- QGridLayout Components in can Span multiple grids as needed
- QBoxLayout and QGridLayout Support ratio The concept of
- ratio Determines the size of the component Relative change
边栏推荐
- Universal dividend source code, supports the dividend of any B on the BSC
- Flutter dynamic | fair 2.5.0 new version features
- Mastering the cypress command line options is the basis for truly mastering cypress
- Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.
- RichView TRVStyle ListStyle 列表样式(项目符号编号)
- Folic acid modified metal organic framework (zif-8) baicalin loaded metal organic framework composite magnetic material (AU- [email
- 记录关于银行回调post请求405 问题
- 解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
- SQL Injection (GET/Select)
- Qt学习20 Qt 中的标准对话框(中)
猜你喜欢

核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon

HALCON联合C#检测表面缺陷——HALCON例程autobahn

SQL Injection (GET/Select)
[email protected] Nanoparticles) | nano metal organic framework carry"/>Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry

FPGA测试方法以Mentor工具为例

Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)

Golang — 命令行工具cobra

Use vscode to view hex or UTF-8 codes

Flutter dynamic | fair 2.5.0 new version features
随机推荐
[how to earn a million passive income]
IBEM 数学公式检测数据集
Go language web development series 30: gin: grouping by version for routing
[556. Next larger element III]
Go: send the get request and parse the return JSON (go1.16.4)
Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email
Selenium browser (1)
Logback log sorting
pytorch 载入历史模型时更换gpu卡号,map_location设置
Function calling convention
Another industry has been broken by Chinese chips. No wonder the leading analog chip companies in the United States have cut prices and sold off
Using registered classes to realize specific type matching function template
Implementation of Muduo asynchronous logging
[combinatorics] permutation and combination (two counting principles, examples of set permutation | examples of set permutation and circle permutation)
mysql中的字段问题
[quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion
Qt学习25 布局管理器(四)
Stack application (balancer)
jvm-运行时数据区
Unity embeddedbrowser browser plug-in event communication