QSplitter(分离部件)

QSplitter(分离部件)QSplitterTheQSplitterclassimplementsasplitterwidget.Asplitterletstheusercontrolthesizeofchildwidgetsbydraggingtheboundarybetweenthem.Anynumberofwidgetsmaybecontrolled…

大家好,又见面了,我是你们的朋友全栈君。

QSplitter

The QSplitter class implements a splitter widget.
A splitter lets the user control the size of child widgets by dragging the boundary between them. Any number of widgets may be controlled by a single splitter. The typical use of a QSplitter is to create several widgets and add them using insertWidget() or addWidget().

QSplitter类实现了一个分离小部件。
splitter允许用户通过拖动子部件之间的边界来控制它们的大小。
任何数量的小部件都可以由单个拆分器控制。QSplitter的典型用法是创建几个小部件并使用
insertWidget()addWidget()添加它们。

看一个例子

这里写图片描述

this->setWindowTitle("码农小明--QSplitter");

    QSplitter* splitter = new QSplitter(this);
    splitter->setFixedSize(500,500);

    QTextEdit* textEdit1 = new QTextEdit();
    QTextEdit* textEdit2 = new QTextEdit();
    QTextEdit* textEdit3 = new QTextEdit();

    splitter->addWidget(textEdit1);
    splitter->addWidget(textEdit2);
    splitter->addWidget(textEdit3);

    textEdit1->setText("Edit1");
    textEdit1->setAlignment(Qt::AlignCenter);

    textEdit2->setText("Edit2");
    textEdit2->setAlignment(Qt::AlignCenter);

    textEdit3->setText("Edit3");
    textEdit3->setAlignment(Qt::AlignCenter);


    this->setFixedSize(500,500);
If a widget is already inside a QSplitter when insertWidget() or addWidget() is called,
it will move to the new position. This can be used to reorder widgets in the splitter later. 
You can use indexOf(), widget(), and count() to get access to the widgets inside the splitter.

如果在调用insertWidget()或addWidget()时,一个小部件已经在QSplitter中,那么它将移动到新的位置。
这可以用于稍后在拆分器中重新排序小部件。您可以使用indexOf()、widget()和count()来访问splitter中的小部件。
qDebug()<<"splitter->count:"<<splitter->count();

这里写图片描述

QSplitter 把 widget 横向的分为 3个widget (默认方向为 横向)

A default QSplitter lays out its children horizontally (side by side); 
you can use setOrientation(Qt::Vertical) to lay its children out vertically.

默认的QSplitter水平地(并排地)布局它的子组件;
你可以使用setOrientation(Qt::Vertical)功能将其子机器人垂直放置。
splitter->setOrientation(Qt::Vertical);//设置方向为垂直

这里写图片描述

QSplitter resizes its children dynamically by default. 
If you would rather have QSplitter resize the children only at the end of a resize operation, 
call setOpaqueResize(false).

默认情况下,QSplitter会动态调整其子元素的大小。如果您希望QSplitter仅在调整大小操作结束时调整子元素的大小,
那么调用setOpaqueResize(false)

默认的true

splitter->setOpaqueResize(true);//默认的true

效果:
这里写图片描述

splitter->setOpaqueResize(false);

效果:
这里写图片描述

区别很明显就是 能不能实时的预览到 拖拽时的画面
The initial distribution of size between the widgets is determined by multiplying
the initial size with the stretch factor. 
The function sizes() returns the sizes set by the user. 
Alternatively, you can save and restore the sizes of the widgets from a 
QByteArray using saveState() and restoreState() respectively.

小部件之间大小的初始分布是通过将初始大小与伸缩因子相乘确定的。
您还可以使用setsize()来设置所有小部件的大小
。函数size()返回用户设置的大小。
或者,您可以分别使用saveState()和restoreState()从QByteArray中保存和恢复小部件的大小。

看一下 void QSplitter::setSizes(const QList<int> &list)

Sets the child widgets' respective sizes to the values given in the list.
If the splitter is horizontal, the values set the width of each widget in pixels,
from left to right. If the splitter is vertical, the height of each widget is set, 
from top to bottom.

将子部件的各自大小设置为列表中给定的值。
如果splitter是水平的,则这些值将以像素为单位设置每个小部件的宽度,从左到右。
如果splitter是垂直的,则从上到下设置每个小部件的高度
    QList<int> list;
    list<<50<<100<<200;//width 为 50 100 200 splitter->setSizes(list);

这里写图片描述

注意:

Note: Adding a QLayout to a QSplitter is not supported (either through setLayout() or
making the QSplitter a parent of the QLayout); use addWidget() instead (see example above).

不支持向QSplitter添加QLayout(通过setLayout()或将QSplitter作为QLayout的父元素);
使用addWidget()代替(参见上面的例子)。

这里写图片描述

    this->setWindowTitle("码农小明--QSplitter");

    QSplitter* splitter = new QSplitter(this);
    splitter->setFixedSize(500,500);

    QTextEdit* textEdit1 = new QTextEdit();
    QTextEdit* textEdit2 = new QTextEdit();
    QTextEdit* textEdit3 = new QTextEdit();
    QTextEdit* textEdit4 = new QTextEdit();


    splitter->addWidget(textEdit1);


    textEdit1->setText("Main-Left");
    textEdit1->setAlignment(Qt::AlignCenter);

    textEdit2->setText("Right-Top");
    textEdit2->setAlignment(Qt::AlignCenter);

    QSplitter* splitter2 = new QSplitter(splitter);
    splitter2->setOrientation(Qt::Vertical);

    splitter2->addWidget(textEdit2);

    textEdit3->setText("Right-Bottom-left");
    textEdit3->setAlignment(Qt::AlignCenter);

    textEdit4->setText("Right-Bottom-right");
    textEdit4->setAlignment(Qt::AlignCenter);

    QSplitter* splitter3 = new QSplitter(splitter2);

    splitter3->addWidget(textEdit3);
    splitter3->addWidget(textEdit4);


    this->setFixedSize(500,500);
        98年菜鸡一枚,请大佬们多多关照!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/125083.html原文链接:https://javaforall.net

(0)
上一篇 2022年4月19日 下午4:00
下一篇 2022年4月19日 下午4:00


相关推荐

  • 计算机科学丛书豆瓣_有关计算机科学与技术专业的书籍

    计算机科学丛书豆瓣_有关计算机科学与技术专业的书籍1.TheArtofComputerProgramming  Author:Donald.E.Knuth  Website:http://www-cs-faculty.stanford.edu/~knuth/taocp.html  BookInfo:这部书被誉为20世纪最重要的20部著作之一,与Einstein的>并列,是计算机科学领域的权威著作.全书共分7卷,目前已经出版了3卷

    2025年6月16日
    7
  • COLMO管线机隐藏安装_五金加工厂的设备清单

    COLMO管线机隐藏安装_五金加工厂的设备清单ActiveXControlReport-GeneratedbyActiveXManagerfrom4Developers. ComputerName:YUERGeneratedOn:Tuesday,November21,2006ControlCount:138ControlName:RefEditControlVersion:1.0Status:

    2022年10月15日
    6
  • CSS绝对定位引发滚动条

    CSS绝对定位引发滚动条CSS 绝对定位超出父元素最大位置导致滚动条 CSS 绝对定位出现滚动条会导致整体布局出现问题 这个情况的出现一般是由于定位的 DIV 宽度超出了屏幕宽度 可以给绝对定位的上一层父 DIV 添加定位属性 再设置隐藏 如此就不会有滚动条 若是只是不需要横向或纵向滚动条则将 overflow 改成 overflow x 或 overflow y 代码如下 divname width 100 position relative overflow hidden 这里需要注意的是 position relative 不加这

    2026年3月18日
    1
  • ARM汇编基础详解

    ARM汇编基础详解ARM 汇编基础详解 1 GNU 汇编语法 2 Cortex A7 常用汇编指令 2 1 处理器内部数据传输指令 2 2 存储器访问指令 2 3 压栈和出栈指令 2 4 跳转指令 2 5 算术运算指令 2 6 逻辑运算指令我们在进行嵌入式 Linux 开发的时候是绝对要掌握基本的 ARM 汇编 因为 Cortex A 芯片一上电 SP 指针还没初始化 C 环境还没准备好 所以肯定不能运行 C 代码 必须先用汇编语言设置好 C 环境 比如初始化 DDR 设置 SP 指针等等 当汇编把 C 环境设置好了以后才可以运行 C 代码

    2026年3月20日
    2
  • WinHTTP Web Proxy Auto-Discovery Service 服务处于 停止 状态「建议收藏」

    WinHTTP Web Proxy Auto-Discovery Service 服务处于 停止 状态「建议收藏」WinHTTPWebProxyAuto-DiscoveryService服务处于停止状态还有,我的服务器没有使用WEB代理和防火墙客户端。但是有一天早上来发现全部电脑都无法上网。PINGISA都不通。重新启动后正常。我检查系统日志里面有3条关于WEB代理的日志:1。TheWinHTTPWebProxyAuto-DiscoveryServicehas…

    2022年6月21日
    53
  • Django(17)orm查询操作「建议收藏」

    Django(17)orm查询操作「建议收藏」前言查找是数据库操作中一个非常重要的技术。查询一般就是使用filter、exclude以及get三个方法来实现。我们可以在调用这些方法的时候传递不同的参数来实现查询需求。在ORM层面,这些查询条件都

    2022年7月29日
    7

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号