当前位置:网站首页>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
边栏推荐
- SQL Injection (AJAX/JSON/jQuery)
- NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
- Shell timing script, starting from 0, CSV format data is regularly imported into PostgreSQL database shell script example
- [机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心
- Selenium browser (1)
- Comprehensive case of MySQL data addition, deletion, modification and query
- 树的深入和广度优先遍历(不考虑二叉树)
- Leetcode-1175.Prime Arrangements
- [combinatorics] permutation and combination (examples of combinatorial number of multiple sets | three counting models | selection problem | combinatorial problem of multiple sets | nonnegative intege
- 金属有机骨架(MOFs)抗肿瘤药载体|PCN-223装载甲硝唑|UiO-66包载盐酸环丙沙星([email protected])
猜你喜欢
Common network state detection and analysis tools
Students who do not understand the code can also send their own token, which is easy to learn BSC
FPGA测试方法以Mentor工具为例
SQL Injection (GET/Select)
Unity embeddedbrowser browser plug-in event communication
Go language unit test 5: go language uses go sqlmock and Gorm to do database query mock
MySQL 数据处理值增删改
Golang - command line tool Cobra
Qt学习24 布局管理器(三)
全面发展数字经济主航道 和数集团积极推动UTONMOS数藏市场
随机推荐
Shell timing script, starting from 0, CSV format data is regularly imported into PostgreSQL database shell script example
解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;
FPGA测试方法以Mentor工具为例
Conversion function and explicit
[how to earn a million passive income]
php 迷宫游戏
Static linked list (subscript of array instead of pointer)
软件测试工作那么难找,只有外包offer,我该去么?
【吉林大学】考研初试复试资料分享
The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can
Go 1.16.4: purpose of go mod tidy
How to use lxml to judge whether the website announcement is updated
信创产业现状、分析与预测
3D vision - 2 Introduction to pose estimation - openpose includes installation, compilation and use (single frame, real-time video)
使用vscode查看Hex或UTF-8编码
Uniapp tips - scrolling components
windos 创建cordova 提示 因为在此系统上禁止运行脚本
Qt学习18 登录对话框实例分析
Qt学习19 Qt 中的标准对话框(上)