当前位置:网站首页>Qt QSplitter拆分器
Qt QSplitter拆分器
2022-07-02 22:07:00 【Mr.codeee】
1.简介
QSplitter拆分器允许用户通过拖动子部件之间的边界来控制它们的大小。
单个拆分器可以控制任意数量的小部件。QSplitter的典型用法是创建几个小部件,并使用insertWidget()或addWidget()添加它们。
2.常用方法
void addWidget(QWidget *widget) | 添加widget |
int count() const | 返回拆分器布局中包含的小部件数量。 |
void setOrientation(Qt::Orientation) | 设置方向,水平,垂直,默认水平的 |
void setStretchFactor(int index, int stretch) | 设置伸缩系数 |
void insertWidget(int index, QWidget *widget) | 插入widget |
默认情况下,QSplitter会动态调整其子元素的大小。如果您希望QSplitter仅在调整大小操作结束时调整子元素的大小, 那么调用setOpaqueResize(false)。
void setOpaqueResize(bool opaque = true)
将子部件的各自大小设置为列表中给定的值。
如果splitter是水平的,则这些值将以像素为单位设置每个小部件的宽度,从左到右。
如果splitter是垂直的,则从上到下设置每个小部件的高度
void setSizes(const QList<int> &list)
3.示例
3.1伸缩系数
添加3个QPlainTextEdit,默认水平方式添加的,并且设置了伸缩系数,我个人理解,伸缩系数,好比,比例系数。上图比例为 2:1:1。
源码:
QSplitter *s1 = new QSplitter(this);
ui->verticalLayout->addWidget(s1);
//添加3个widget
QPlainTextEdit *t1 = new QPlainTextEdit(s1);
t1->setPlaceholderText("t1");
QPlainTextEdit *t2 = new QPlainTextEdit(s1);
t2->setPlaceholderText("t2");
QPlainTextEdit *t3 = new QPlainTextEdit(s1);
t3->setPlaceholderText("t3");
s1->addWidget(t1);
s1->addWidget(t2);
s1->addWidget(t3);
s1->setStretchFactor(0,2);
s1->setStretchFactor(1,1);
s1->setStretchFactor(2,1);
3.2 setOpaqueResize(false)效果
默认为true,效果如下
3.3QSplitter相互嵌套
源码:
QSplitter *mainSplitter = new QSplitter(this);
ui->verticalLayout->addWidget(mainSplitter);
QSplitter *rightSplitter = new QSplitter(mainSplitter);
rightSplitter->setOrientation(Qt::Vertical); //设置垂直方向
//添加3个widget
QPlainTextEdit *t1 = new QPlainTextEdit(mainSplitter);
t1->setPlaceholderText("t1");
QPlainTextEdit *t2 = new QPlainTextEdit(rightSplitter);
t2->setPlaceholderText("t2");
QPlainTextEdit *t3 = new QPlainTextEdit(rightSplitter);
t3->setPlaceholderText("t3");
rightSplitter->addWidget(t2);
rightSplitter->addWidget(t3);
mainSplitter->addWidget(t1);
mainSplitter->addWidget(rightSplitter);
边栏推荐
- NC24325 [USACO 2012 Mar S]Flowerpot
- 傑理之修改不需要長按開機功能【篇】
- go 多线程数据搜索
- Socket socket c/s end process
- [ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)
- Dahua cloud native load balancing article - the passenger flow of small restaurants has increased
- Commodity information management system (C language document version)
- U++ learning note pile
- How can I use knockout's $parent/$root pseudovariables from inside a . computed() observable?
- Golang's learning route
猜你喜欢
Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed
Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)
NC50965 Largest Rectangle in a Histogram
odoo13搭建医院HRP环境(详细步骤)
Task and privilege level protection
杰理之、产线装配环节【篇】
位的高阶运算
[LeetCode] 反转字符串中的单词 III【557】
Wait to solve the zombie process
[chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?
随机推荐
建立自己的网站(22)
DTM distributed transaction manager PHP collaboration client V0.1 beta release!!!
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
Wait to solve the zombie process
PHP implements querying the data matching the date of birth according to the entered age
Graphic view frame
Objects and object variables
[LeetCode] 数组中的第K个最大元素【215】
Jatpack------LiveData
Jatpack------LiveData
Oracle-PL/SQL编程
Gas station [problem analysis - > problem conversion - > greed]
go 条件变量
How should programmers write logs
解决 excel 文件上传时更改选中的文件出现错误net::ERR_UPLOAD_FILE_CHANGED
Zhong Xuegao responded that the product will not melt for 1 hour: it contains solid components and cannot melt into water
【板栗糖GIS】arcmap—如何批量修改注记要素的字体,颜色,大小等
Notes on key vocabulary in the English original of the biography of jobs (10) [chapter eight]
[error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')
PMP项目整合管理