当前位置:网站首页>QT qsplitter splitter
QT qsplitter splitter
2022-07-02 22:54:00 【Mr.codeee】
1. brief introduction
QSplitter The splitter allows users to control the size of subassemblies by dragging the boundaries between them .
A single splitter can control any number of widgets .QSplitter The typical use of is to create several widgets , And use insertWidget() or addWidget() Add them .
2. Common methods
| void addWidget(QWidget *widget) | add to widget |
| int count() const | Returns the number of widgets contained in the splitter layout . |
| void setOrientation(Qt::Orientation) | Set the direction , level , vertical , Default horizontal |
| void setStretchFactor(int index, int stretch) | Set the expansion coefficient |
| void insertWidget(int index, QWidget *widget) | Insert widget |
By default ,QSplitter Will dynamically adjust the size of its child elements . If you wish QSplitter Adjust the size of child elements only at the end of the resizing operation , So called setOpaqueResize(false).
void setOpaqueResize(bool opaque = true)
Set the respective sizes of the subassemblies to the values given in the list .
If splitter It's horizontal , Then these values will set the width of each widget in pixels , From left to right .
If splitter It's vertical , Then set the height of each widget from top to bottom
void setSizes(const QList<int> &list)
3. Example
3.1 Expansion coefficient

add to 3 individual QPlainTextEdit, Added in the default horizontal way , And set the expansion coefficient , I personally understand , Expansion coefficient , like , ratio . The scale of the above figure is 2:1:1.
Source code :
QSplitter *s1 = new QSplitter(this);
ui->verticalLayout->addWidget(s1);
// add to 3 individual 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) effect

The default is true, The effect is as follows

3.3QSplitter Nesting with each other

Source code :
QSplitter *mainSplitter = new QSplitter(this);
ui->verticalLayout->addWidget(mainSplitter);
QSplitter *rightSplitter = new QSplitter(mainSplitter);
rightSplitter->setOrientation(Qt::Vertical); // Set the vertical direction
// add to 3 individual 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);边栏推荐
- `Usage of ${}`
- P7072 [CSP-J2020] 直播获奖
- 數據分析學習記錄--用EXCEL完成簡單的單因素方差分析
- 杰理之样机在多次触摸后会触发关机【篇】
- UE4 UI adaptive screen
- Jatpack------LiveData
- Baidu AI Cloud - create a face recognition application
- [LeetCode] 多数元素【169】
- 世界环境日 | 周大福用心服务推动减碳环保
- [chestnut sugar GIS] ArcMap - how to batch modify the font, color, size, etc. of annotation elements
猜你喜欢
![[leetcode] most elements [169]](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[leetcode] most elements [169]

世界环境日 | 周大福用心服务推动减碳环保

Objects and object variables

SimpleITK使用——4. 奇怪的问题

数据分析学习记录--用EXCEL完成简单的单因素方差分析

Utilisation de simpletk - 4. Question étrange

World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection

Addition, deletion, modification and query of handwritten ORM (object relationship mapping)

【板栗糖GIS】global mapper 如何通过dsm批量制作贴地等高线

数学建模——图与网络模型及方法(一)
随机推荐
世界环境日 | 周大福用心服务推动减碳环保
boot actuator - prometheus使用
Rails 3 activerecord: sort by association count - rails 3 activerecord: order by count on Association
百度智能云-创建人脸识别应用
【洛谷P1541】乌龟棋【DP】
杰理之如何测试按键的误触率【篇】
Performance optimization - rigorous mode
杰理之内置关机电流 1.2uA,之后不能长按开机【篇】
牛客网:最大子矩阵
[LeetCode] 反转字符串【344】
钟薛高回应产品1小时不化:含固体成分 融化不能变成水
存储单位换算
U++ learning note pile
#include errors detected. Please update your includePath.
E-commerce system microservice architecture
Task and privilege level protection
附加:【登录信息存储】与【登录状态校验】;(包括:总结了到目前为止,有关【登录信息存储】与【登录状态校验】的所有内容;)
U++ learning notes - relaxation
任务和特权级保护
高并发介绍及应对