当前位置:网站首页>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);
边栏推荐
- 数据分析学习记录(二)---响应曲面法及Design-Expert的简单使用
- [leetcode] there are duplicate elements [217]
- PHP wechat red packet grabbing algorithm
- 大话云原生之负载均衡篇-小饭馆客流量变大了
- [leetcode] reverse string [344]
- Server response status code
- Performance optimization - rigorous mode
- P1007 独木桥
- [error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')
- Build your own website (22)
猜你喜欢
SimpleITK使用——4. 奇怪的問題
Oracle PL / SQL programming
Graphic view frame
数据分析学习记录--用EXCEL完成简单的单因素方差分析
[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)
[NPUCTF2020]ezlogin xPATH注入
boot actuator - prometheus使用
#include errors detected. Please update your includePath.
`${}`的用法
Baidu AI Cloud - create a face recognition application
随机推荐
小鹏P7出事故,安全气囊未弹出,这正常吗?
[NPUCTF2020]ezlogin xPATH注入
[LeetCode] 反转字符串【344】
送给即将工作的自己
Struct, bit segment, enumeration, union
How can I use knockout's $parent/$root pseudovariables from inside a . computed() observable?
P1007 独木桥
原生js添加样式的方法
大一学习分享
How should programmers write logs
#include errors detected. Please update your includePath.
Server response status code
【板栗糖GIS】arcmap—如何批量修改注记要素的字体,颜色,大小等
Go 4 modes Singleton
杰理之内置关机电流 1.2uA,之后不能长按开机【篇】
[LeetCode] 存在重复元素【217】
go 4种单例模式
[leetcode] most elements [169]
go 多线程数据搜索
Uniapp wechat login returns user name and Avatar