当前位置: 首页 > article >正文

Qt常用控件之垂直布局QVBoxLayout

垂直布局QVBoxLayout

QVBoxLayout 是一种垂直布局控件。

1. QVBoxLayout属性

属性说明
layoutLeftMargin左侧边距。
layoutRightMargin右侧边距。
layoutTopMargin顶部边距。
layoutBottomMargin底部边距。
layoutSpacing相邻元素间距。

2. QVBoxLayout方法

方法说明
addWidget把控件添加到布局管理器。
setLayout设置布局管理器到……(即设置到 widget 中或其他 layout 中)

3. 代码创建并使用QVBoxLayout管理多个控件

注意要将 QVBoxLayout 的父元素设置到 this 上,且 QVBoxLayout 头文件为 <QLayout>

#include "widget.h"
#include "ui_widget.h"
#include <QPushButton>
#include <QLayout>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QPushButton* button1=new QPushButton("pushButton1");
    QPushButton* button2=new QPushButton("pushButton2");
    QPushButton* button3=new QPushButton("pushButton3");

    QVBoxLayout* layout=new QVBoxLayout(this);
    layout->addWidget(button1);
    layout->addWidget(button2);
    layout->addWidget(button3);
}

Widget::~Widget()
{
    delete ui;
}

QVBoxLayout1

代码构建的 layout 的特点是布局会随窗口大小变化而变化。


http://www.kler.cn/a/584426.html

相关文章:

  • Leetcode9-回文数
  • 解决:外部调用存储过程时突然变慢,但是在sql server运行很快
  • ChromeOS 134 版本更新
  • 专业视角:set 和 multiset的原理与应用解析
  • (2025|ICLR|厦大华为,LoSA,基于表示互信息的动态层级稀疏率,基于重构误差的秩分配)LLM 的动态低秩稀疏自适应
  • SQL Server数据库基于SQL性能优化
  • 迪威 3D 模型发布系统:制造业产品展示革新利器
  • 批量给 Excel 添加或删除密码保护|Excel 批量设置打开密码和只读密码
  • 【3dmax笔记】008:选择工具
  • 数字隔离器,如何提升储能系统的安全与效能?
  • k8s集群中部署dcgm-exporter收集GPU指标
  • 5-27 临摹大师-IP-Adapter
  • 【Docker项目实战】使用Docker与Caddy部署BanBan任务管理工具
  • 如何搭建一个适配微信小程序,h5,app的uni-app项目
  • C# NX二次开发:获取模型中所有的草图并获取草图中的对象
  • 基于SpringBoot + Vue 的校园论坛系统
  • K8S学习之基础二十六:k8s的StatefulSet控制器
  • 在 Ubuntu 上安装和配置 Docker 的完整指南
  • 网络爬虫-1:发送请求+维持会话+代理设置/超时设置
  • 高德爬取瓦片和vue2使用