当前位置:网站首页>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);边栏推荐
- Golang面试整理 三 简历如何书写
- 數據分析學習記錄--用EXCEL完成簡單的單因素方差分析
- How should programmers write logs
- 加油站[问题分析->问题转换->贪心]
- Task and privilege level protection
- [micro service sentinel] rewrite Sentinel's interface blockexceptionhandler
- 杰理之样机在多次触摸后会触发关机【篇】
- Golang的学习路线
- Using rendertext() to output multiple lines of text with rendertext() in R shiny
- Build your own website (22)
猜你喜欢

数组进阶提高
![[leetcode] most elements [169]](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[leetcode] most elements [169]

手写ORM(对象关系映射)增删改查
![[羊城杯2020]easyphp](/img/12/da28f738e50e625b0a66a94af3703d.png)
[羊城杯2020]easyphp

Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed

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

uniapp微信登录返显用户名和头像

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)

Commodity information management system (C language document version)
随机推荐
图形视图框架
Dahua cloud native load balancing article - the passenger flow of small restaurants has increased
`Usage of ${}`
Source code analysis - lightweight asynchronous crawler framework Ruia
[LeetCode] 存在重复元素【217】
附加:【登录信息存储】与【登录状态校验】;(包括:总结了到目前为止,有关【登录信息存储】与【登录状态校验】的所有内容;)
杰理之直接触摸样机的顶针反应不正常【篇】
[chestnut sugar GIS] ArcMap - how to batch modify the font, color, size, etc. of annotation elements
[chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?
[LeetCode] 数组中的第K个最大元素【215】
kubernetes 使用主机名将 pod 分配在指定节点上
Golang's learning route
Rails 3 activerecord: sort by association count - rails 3 activerecord: order by count on Association
Film and television excerpts
Utilisation de simpletk - 4. Question étrange
PHP implements querying the data matching the date of birth according to the entered age
Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed
stop slave卡住--事务的事件没有复制完整
Server response status code
百度智能云-创建人脸识别应用