当前位置:网站首页>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
边栏推荐
- 小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。
- Go language web development series 30: gin: grouping by version for routing
- 3D vision - 2 Introduction to pose estimation - openpose includes installation, compilation and use (single frame, real-time video)
- HALCON联合C#检测表面缺陷——HALCON例程autobahn
- [how to earn a million passive income]
- 【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
- Disruptor -- a high concurrency and high performance queue framework for processing tens of millions of levels
- 金属有机骨架材料ZIF-8包载姜黄素([email protected]纳米颗粒)|纳米金属有机框架搭载雷帕霉素|科研试剂
- UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
- 项目协作的进度如何推进| 社区征文
猜你喜欢

Conversion function and explicit

Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue

28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;

Flutter dynamic | fair 2.5.0 new version features
![Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:](/img/2f/33504391a661ecb63d42d75acf3a37.png)
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:

MySQL data processing value addition, deletion and modification

Go language unit test 4: go language uses gomonkey to test functions or methods

The solution of Chinese font garbled code in keil5

3D vision - 2 Introduction to pose estimation - openpose includes installation, compilation and use (single frame, real-time video)

Dlopen() implements dynamic loading of third-party libraries
随机推荐
SQL Injection (GET/Search)
[combinatorics] permutation and combination (examples of combinatorial number of multiple sets | three counting models | selection problem | combinatorial problem of multiple sets | nonnegative intege
信创产业现状、分析与预测
Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry
从零开始的基于百度大脑EasyData的多人协同数据标注
金属有机骨架MOFs装载非甾体类抗炎药物|ZIF-8包裹普鲁士蓝负载槲皮素(制备方法)
Mastering the cypress command line options is the basis for truly mastering cypress
[ACNOI2022]猜数
Qt学习22 布局管理器(一)
RocksDB LRUCache
Go language unit test 4: go language uses gomonkey to test functions or methods
Leetcode-1175. Prime Arrangements
Mobile phones and computers can be used, whole people, spoof code connections, "won't you Baidu for a while" teach you to use Baidu
GoLand 2021.1: rename the go project
金属有机骨架(MOFs)抗肿瘤药载体|PCN-223装载甲硝唑|UiO-66包载盐酸环丙沙星([email protected])
Windos creates Cordova prompt because running scripts is prohibited on this system
Common network state detection and analysis tools
挡不住了,国产芯片再度突进,部分环节已进到4nm
Failure of vector insertion element iterator in STL
[技术发展-24]:现有物联网通信技术特点