addStretch、setStretchFactor用法

Qt 分裂布局部件可伸缩setStretchFactor() 分裂布局部件可伸缩setStretchFactor() layout->setStretchFactor(list,1):设定可伸缩控件,第一个参数用于指定设置的控件(序号从0起编号),第2个参数的值大于0则表示此控件为可伸缩控件。 用一句话来表示我对setStretchFactor(list,1)的理解吧:就是说,如果设置了可伸缩控件,则该控件对应的窗口,在进行缩放的时候,该控件 阅读详情
AI摘要

本文详细介绍了Qt布局器中addStretch、setStretch、insertStretch和setStretchFactor函数的使用,展示了如何调整按钮间的间距和元素伸缩比例,适用于理解和优化UI布局。

目录

1.前言

2.addStretch

3.setStretch

4.insertStretch

5.setStretchFactor


1.前言

Qt布局器中和Stretch相关的方法有:

  • addStretch
  • setStretch
  • insertStretch
  • setStretchFactor

当然还包括它们对应的获取函数(如:stretch函数)。今天对这几个函数做个总结。

2.addStretch

如下代码为没调用addStretch函数:

QtWidgetsApplication2::QtWidgetsApplication2(QWidget *parent)
    : QWidget(parent)
{
    ui.setupUi(this);
 
    auto pBtn1 = new QPushButton("btn1", this);
    auto pBtn2 = new QPushButton("btn2", this);
    auto pBtn3 = new QPushButton("btn3", this);

    auto pLayout = new QHBoxLayout(this);
    pLayout->addWidget(pBtn1);
    pLayout->addWidget(pBtn2);
    pLayout->addWidget(pBtn3);
    
    setLayout(pLayout);
 
}

结果如下:

图1:没有addStretch函数

 如下代码为调用addStretch函数:

QtWidgetsApplication2::QtWidgetsApplication2(QWidget *parent)
    : QWidget(parent)
{
    ui.setupUi(this);
 
    auto pBtn1 = new QPushButton("btn1", this);
    auto pBtn2 = new QPushButton("btn2", this);
    auto pBtn3 = new QPushButton("btn3", this);

    auto pLayout = new QHBoxLayout(this);
    pLayout->addStretch(1);
    pLayout->addWidget(pBtn1);
    pLayout->addStretch(1);
    pLayout->addWidget(pBtn2);
    pLayout->addStretch(1);
    pLayout->addWidget(pBtn3);
    pLayout->addStretch(6);
    setLayout(pLayout);
 
}

结果如下:

                                 图2:调用了addStretch函数,按钮之间空隙没有用红色方框标记

     图3:调用了addStretch函数,按钮之间空隙用红色方框标记

其中四个addStretch()函数用于在button按钮间增加伸缩量,伸缩量的比例为1:1:1:6,意思就是将button以外的空白地方(如:图3中红色方框所示)按设定的比例等分为9份并按照设定的顺序放入buttonLayout布局器中。如下代码:

3.setStretch

可以通过调用setStretch函数对布局器中指定索引窗体或QLayoutItem对象占据布局的区域比例进行更改。注意:如果指定的索引不存在,则调用setStretch函数设置的stretch值无效,布局器将采用默认的stretch值。如下代码:

QtWidgetsApplication2::QtWidgetsApplication2(QWidget *parent)
    : QWidget(parent)
{
    ui.setupUi(this);
 
    auto pBtn1 = new QPushButton("btn1", this);
    auto pBtn2 = new QPushButton("btn2", this);
    auto pBtn3 = new QPushButton("btn3", this);

    auto pLayout = new QHBoxLayout(this);
    pLayout->setStretch(0, 1);
    pLayout->addWidget(pBtn1);
    pLayout->addStretch(1);
    pLayout->addWidget(pBtn2);
    pLayout->addStretch(1);
    pLayout->addWidget(pBtn3);
    pLayout->addStretch(6);

    pLayout->setStretch(0, 10);
    setLayout(pLayout);
 
}

第11行代码,因为调用setStretch时,布局器里啥都没有,是空的,故0索引值是无效值,此时setStretch无效。

第19行代码将布局器中索引为0的对象也即按钮pBtn1占据整个布局器的Stretch值设置为10,结果按钮pBtn1占据整个布局器区域明显比以前增大了,如下:

当将第19行setStretch函数的索引改为1,即设置按钮1和按钮2之间的空白区域占比为10,结果如下:

4.insertStretch

insertStretch和settStretch类似,不再赘述。

5.setStretchFactor

如下代码:

QtWidgetsApplication2::QtWidgetsApplication2(QWidget *parent)
    : QWidget(parent)
{
    ui.setupUi(this);
 
    auto pBtn1 = new QPushButton("btn1", this);
    auto pBtn2 = new QPushButton("btn2", this);
    auto pBtn3 = new QPushButton("btn3", this);

    auto pLayout = new QHBoxLayout(this);
   
    pLayout->addWidget(pBtn1);
    pLayout->addWidget(pBtn2);
    pLayout->addWidget(pBtn3);

    pLayout->setStretchFactor(pBtn1, 1);
    pLayout->setStretchFactor(pBtn2, 2);
    pLayout->setStretchFactor(pBtn3, 4);
    setLayout(pLayout);

}

结果如下:

含义显而易见:就是pBtn1占据三个3按钮总长的1/7, pBtn2占据三个3按钮总长的2/7, pBtn3占据三个3按钮总长的4/7。

   类似的函数还有QGridLayout类的setRowStretch、setColumnStretch,用法基本相同。

Qt学习12:常用Layout布局方式总结 Qt学习记录:常用布局QBoxLayout,QGridLayout,QFormLayout,QStackedLayout,QTabWidget,QStackedWidget,QSplitter等类详解 阅读详情

相关推荐

QSplitter设置比例setStretchFactor失效的问题

1.调用QSplitter->addWidget( ),传参必须是QWidget类型,不能是QWidget的派生类,比如QTabWidget,QPushButton等等。总结就是严格按照下面两点要求使用QSplitter就不会存在setStretchFactor失效的问题。2.如果其中有一个子窗口设置了layout,哪个其他子窗口必须也要设置layout。网上查了很多,比如设置子窗口SizePolicy,都不起作用。按上面的代码执行setStretchFactor是无效的。

liumy_2013的博客 1217

QT中布局器的addStretch()函数使用

http://blog.csdn.net/zhangxufei/article/details/50825057 addStretch() void QBoxLayout::addStretch(int stretch = 0) Adds a stretchable space (a QSpacerItem) with zero minim

Tim的嵌入式之旅 1万+

Qt布局系统与高分屏适配全解析:面试必考实战指南

Qt 的布局系统是面试里的"必考送分题"——但很多人只会拖控件,一问原理就懵。这篇文章把 QLayout 家族、SizePolicy、弹性空间、Qt6 高 DPI 适配一条线串清楚,代码全部能跑,看完直接上考场。知识点核心 API / 概念一句话要点水平/垂直布局最常用,支持嵌套组合网格布局表单布局addRow(label, field) 自动对齐弹性空间stretch 是弹簧,spacing 是固定棍伸缩因子给控件分配空间的比例权重尺寸策略。

SHIXINGYA的专栏 125

Python Qt GUI设计:如何调整组件布局比例?(拓展篇—1)

Python Qt GUI设计:如何调整组件布局比例?(拓展篇—1)

qq_44597856的博客 925

基于FPGA的心电信号实时处理与智能诊断系统实现【附源码解析】

本文详细介绍了基于FPGA的心电信号实时处理与智能诊断系统的设计与实现。系统通过高精度采集电路和FPGA数字滤波技术处理微弱心电信号,采用自适应算法准确检测QRS波群,实现心率计算和心律异常诊断。附源码解析展示了FIR滤波器、中值滤波器和诊断逻辑的Verilog实现,为心电监护系统开发提供实用参考。

g8f9d0s1a2的博客 774

OCR开发实战:如何用PaddleOCR C++版实现本地文字识别(附模型文件处理技巧)

本文详细介绍了如何使用PaddleOCR C++版实现本地文字识别,包括环境搭建、工程编译、运行时优化等全流程。重点讲解了在VS2019/VS2022环境下配置PaddleOCR的CPU推理性能优化技巧,以及模型文件处理的实际应用方法,帮助开发者高效完成OCR本地化部署。

devops8pract的博客 343

Qt addStretch()

addStretch函数,是在布局的时候用到。 函数原型: void QBoxLayout::addStretch ( int stretch = 0 ) 作用:平均分配Layout 比如: QVBoxLayout *buttonLayout = new QVBoxLayout; buttonLayout->addStretch(1); buttonLayout->ad

sunxiaopengsun的专栏 1566

西门子1500T系列凸轮同步(CAMIN指令用法)

添加凸轮工艺对象(TO_CAM),也就是凸轮表。开始编程,先写2个轴的使能、回原点与主轴的定位。监控主轴与从轴的位置、速度关系是否满足实验要求。1.添加工艺对象(1个定位轴,1个同步轴)调用CAMIN指令 ,凸轮耦合。主轴为旋转轴且为模数轴。3.调用插补凸轮盘指令。4.仿真、监控、调试。

gyxgyx789的博客 1万+

Qt中addStretch函数介绍

addStretch 是 Qt 框架中布局管理器(如 QHBoxLayout、QVBoxLayout)的一个函数,用于在布局中添加弹性空间。addStretch() 函数会在布局中插入一个可伸缩的空间(或称为弹簧),用于控制布局中各组件的间距和对齐方式。(2) insertStretch(int index, int stretch = 0):在指定位置插入弹性空间。(1) addSpacing(int size):添加固定大小的空间。(4)在复杂的布局中,合理使用弹性空间可以创建响应式的界面布局。

kupePoem的专栏 777

强化学习 reward 曲线可视化:从基础绘制到顶刊级对比分析

本文详细介绍了强化学习reward曲线的可视化方法,从基础绘制到顶刊级对比分析。通过matplotlib和seaborn的实战示例,展示了如何优化曲线图的视觉效果,包括多实验对比、置信区间添加和分面图应用。文章还分享了顶刊级图表的进阶技巧,如字体排版、颜色选择和关键标注,帮助研究者提升论文图表质量。

weixin_29096377的博客 278

SAP Fiori Launchpad 自定义层文本翻译实战:精准修正 Tile、Catalog 与 Group 标题

SAP Fiori 项目中,入口层(tile/catalog/group)的翻译问题常被忽视,但其直接影响用户体验。与前端i18n不同,这些文本属于平台配置数据,需通过ABAP标准翻译流程(SE63)处理。关键步骤包括:使用/UI2/FLC定位Text ID和Configuration ID,根据前缀区分Main/Property WD Config Key,在SE63中锁定WDY_CONF_USERT2表对象进行翻译。操作时需注意使用系统源语言环境,翻译完成后可能需要清理缓存。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 190

Qt中的addStretch函数的作用

addStretch函数,是在布局的时候用到。 函数原型: void QBoxLayout::addStretch ( int stretch = 0 ) 作用:平均分配Layout 比如: QVBoxLayout *buttonLayout = new QVBoxLayout; buttonLayout->addStretch(1); buttonLayout->addWid

loster_Li的博客 9297

vue3 - 最新详细实现高德地图绘制动态热力图详细教程,在某区域或城市地图上做“热力图层“展示人流量、旅游人口密度、热量图、全国地区地理热力图,利用颜色的深浅表示密度或强度等场景(详细示例代码教程)

vue3,nuxt3,高德地图,热力图,绘制热力图层,人流量,vue3使用高德地图实现某个区域热力图,vue3高德地图api加载热力图及关闭,接收热力图数据并渲染热力图,关掉热力图,Vue使用高德API制作热力图,热力图加载不出来,电子围栏围住热力图,vue3中使用高德地图渲染热力图组件,高德地图使用热力图详细教程,报错,卡顿,出不来怎么办,无法关闭,怎么解决这个问题,出错,城市名称,城市某个街道,城区,省份,市区,县城,乡镇,村,各省份的热力图,交通流量,人口流量,密度,旅游出行,人口数量,颜色介绍,深浅

✅ 精选推荐文章 5222

Qt addStretch()详解

addStretch函数,是在布局的时候用到。 函数原型:void QBoxLayout::addStretch ( int stretch = 0 ) 作用:平均分配Layout 比如: QVBoxLayout *buttonLayout = new QVBoxLayout; buttonLayout->addStretch(1); buttonLayout->...

weixin_30588827的博客 810

YOLOv8改进 | 特殊场景检测篇 | 最新的多尺度特征提取DICAM(全网独家首发,增强水下图像的质量)

本文给大家带来的最新改进机制是多尺度特征提取和通道注意力机制DICAM,深度Inception和通道注意力模块(DICAM)主要用于用于增强水下图像的质量、对比度和色偏。所提出的DICAM模型考虑了水下图像的比例退化和不均匀色偏,从而提高图像的质量。通过在两个公开的水下图像增强数据集上的广泛实验,验证了提出的模型在全参考和无参考图像质量评估指标方面。欢迎大家订阅我的专栏一起学习YOLO,购买专栏读者联系读者入群获取进阶项目文件!

Snu77的博客 2230

23种设计模式-享元(Flyweight)设计模式

软考中级-软件设计师 享元设计模式

片言可决讼,半纸能缚龙 3238

QT 布局管理器(QHBoxLayout/QVBoxLayout/QGridLayout)

1、setcontentmargins设置四周留白(相对于整个窗口的)的间隔;函数原型:void QLayout::setContentsMargins ( int left, int top, int right, int bottom )。 layout1->setContentsMargins(1,0,1,0); 2、setMargin()在控件内部的边距设置。 3、addStretch()在布局里面添加弹簧。 4、setspacing设置控件之间的间隔;注:设置无效的可能原因有,总布

ligare的博客 3118

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

读QT Creator源码学习笔记(一)

读QT Creator源码学习笔记 注:QT Creator版本4.15 记录阅读过程中需要掌握的基础知识(基础参考:《》) Welcome setAutoFillBackground 当使用QPalette为窗口设定背景并使用QPalette::Window时必须调用setAutoFillBackground(true) 参考:《Qt中setAutoFillBackgroundQt中setAutoFillBackgroundQt中setAutoFillBackground》.

baidu_41388533的博客 266

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

QT 布局管理器设置控件固定大小,控件间隔

布局管理器刚开始用的时候,会出现比例不是自己想要的,又或者自动缩放尺寸不理想,这个时候就会想要设置布局管理器中控件的大小,达到理想布局。 使用函数: 1.设置布局管理器内部尺寸比例: QVBoxLayout::setStretchFactor(Qlayout *1,int); Qlayout *1:添加的控件 int:所占布局管理器的比例 //例: QVBoxLayout::setStretchFactor(btn1,2); QVBoxLayout::setStretchFactor(btn

qq_51150032的博客 2万+

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

QBOXLayout:QHBoxLayout和QVBoxLayout类

前言采用QBOXLayout类可以在水平和垂直方向上排列控件,QHBoxLayout和QVBoxLayout类继承自QBoxLayout采用QHBoxLayout类,按照从左到右的顺序来添加控件。

zxf347085420的博客 572

Qt 布局常用方法

Qt的布局有下列多种 QBoxLayout 水平或垂直排列控件 QButtonGroup 组织按钮的容器 QFormLayout 管理输入控件和其相关的标签 QGraphicsAnchor 表示在QGraphicsAnchorLayout中两个项目之间的锚 QGraph...

风云的的博客 5086

Qt 之水平/垂直布局(QHBoxLayout、QVBoxLayout)

QBoxLayout可以在水平方向或垂直方向上排列控件,由QHBoxLayout、QVBoxLayout所继承。

青春不老,奋斗不止! 12万+

Qt水平/垂直布局

背景: 在现有的ui的顶端放置自定义的状态栏。Qt中的布局,可以使用QDesigner直接拖放,同样可以手写(稍显麻烦),但是常用在小部件的叠加布局上。 常见类是QBoxLayout及其子类QHBoxLayout和QVBoxLayout。 其中H代表horizon,意思是水平,即表示QHBoxLayout是水平布局。 其中V代表vertical,意思是垂直,即表示QVBoxLayout是垂...

Poseidon's Maserati 2429

QT垂直布局和水平布局

1.解释  QBoxLayout:可以在水平方向或垂直方向上排列控件,由QHBoxLayout、QVBoxLayout所继承。  QHBoxLayout:水平布局,在水平方向上排列控件。  QVBoxLayout:垂直布局,在垂直方向上排列控件。  同时我们注意到水平布局、垂直布局除了构造时的方向(LeftToRight、TopToBottom)不同外,其它均相同。2.示例代码  2.1QHBox...

希哈科技 6350
上一篇: Qt::ApplicationAttribute各枚举值含义
下一篇: Colliding Mice碰撞老鼠工程分析
荆楚闲人
博客等级 码龄20年 3万+粉丝 472原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值