QGridLayout类

Qt中的QGridLayout网格布局类下的两种不同的addWidget功能 在Qt中的QGridLayout网格布局类中,有许多基类自带的函数,在这里,我主要介绍一下其中的一个函数,addWidget函数,在我的仿真实验中,运用到了这个函数,这个函数的两种不同的功能都被我使用到了,故在这里进行介绍。 addWidget第一种功能: void QGridLayout::addWidget(QWidget *widget, int row, int column, Qt::Alignment alignment = Qt::Alignment()) 这是这个函数的第一种功能,第一个参 阅读详情

QGridLayout类在网格中布置控件。


Header:#include <QGridLayout>
CMake:find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake:QT += widgets
Inherits:<<< QLayout

【详细描述】

QGridLayout 将通过父布局 parent layout 或 parentWidget()提供给它的空间划分为行和列,并将其管理的每个控件放入对应的单元格。

行和列的行为相同且有等效的函数,这里我们只讨论列。

每列都有一个最小的宽度和一个拉伸系数。

 最小宽度 是“使用setColumnMinimumWidth()设置集合中的最大宽度”以及“该列中每个控件的最小宽度值”的较大值 。

 拉伸因子 以列为例,使用setColumnStretch()设置列拉伸,并确定列将获得多少可用空间,并超过其必要的最小值。

通常,每个控件widget或布局layout使用addWidget()放入自己的单元格中。一个控件也可以使用 addItem() 和addWidget() 跨越行和列以占用多个单元格。如果是这样,QGridLayout将基于拉伸系数来猜测如何在行列上分配大小。

removeWidget()用于从布局中删除控件。在控件上调用QWidget::hide()也会有效地从布局中删除控件,并能通过调用QWidget::show()重新显示。

下图对话框包含了一个5列3行的网格:

对话框切片中的第0、第2 和第4列各由一个QLabel,QLineEdit,QListBox组成。第 0 行由三个QLabel组成,第 1 行由三个QLineEdit组成,第 2 行由三个QListBox组成。

第1和第3 列是用setColumnMinimumWidth()构成的占位符来获得列之间的适当空间。

请注意:列和行的宽度或高度均不相等。如果希望两列具有相同的宽度,必须使用setColumnMinimumWidth() 和 setColumnStretch() 自行设置它们的最小宽度和拉伸系数。

如果QGridLayout不是顶级布局(即并不管理控件的所有区域和子项),则必须在创建它时将其添加到其父布局中。添加的一般做法是在父布局上调用addLayout() 。

布局添加后,就可以开始使用 addWidget(), addItem()和addLayout()将控件和其他布局放入网格布局的单元格中了。

QGridLayout 还包括两个边距宽度:内容边距contents margin和 spacing()。

 内容边距 是沿着每个QGridLayout的四个边的保留空间的宽度。

spacing()  是相邻方框之间自动分配的间距的宽度。

默认内容边距值由style类提供。Qt styles指定的默认值为9px(子控件)和11px(窗口)。边距间距默认为与顶级布局的相同,或与父布局相同。

参见  QBoxLayout, QStackedLayout, Layout Management 和 Basic Layouts Example。


【属性】

此属性保存并排布局的控件间距。如未显式设置,则布局的水平间距将从父布局或父构件的样式中继承。以下是访问函数:

inthorizontalSpacing() const
voidsetHorizontalSpacing(int spacing)

此属性保存垂直布局的控件间距。如果未显式设置,则布局的垂直间距将从父布局或父构件的样式设置继承。以下是访问函数:

intverticalSpacing() const
voidsetVerticalSpacing(int spacing)

【公有函数】

QGridLayout(QWidget *parent = nullptr)

在父控件parent构造一个新的QGridLayout,该布局最初只有一行一列,在插入新项目时将展开。

布局会直接设置为parent的顶级布局。一个widget只能有一个顶级布局,它由QWidget::layout()返回。

如果parent = nullptr,则必须将此QGridLayout插入到另一个layout中,或使用QWidget::setLayout()将其设置为控件布局。

virtual~QGridLayout()
voidaddItem(QLayoutItem *item, int row, int column, int rowSpan = 1, int columnSpan = 1, Qt::Alignment alignment = Qt::Alignment())

新item项在row、column位置添加,跨越rowSpan行、columnSpan列,如果rowSpan 或 columnSpan 值设为 -1,则该项将分别延伸到底部或右边缘。新建item从属于当前布局。

voidaddLayout(QLayout *layout, int row, int column, Qt::Alignment alignment = Qt::Alignment())
新layout放在网格的 (row, column)位置,左上角的位置是(0, 0),对齐方式由alignment 指定,默认为0,表示新layout将填充整个单元格。非零对齐方式表示布局不应增长以填满可用空间,而应根据sizeHint()调整大小。新layout是当前网格布局的子项。
voidaddLayout(QLayout *layout, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment = Qt::Alignment())

此重载版本增加了跨越rowSpan行、columnSpan列参数,如果rowSpan 或 columnSpan 值设为 -1,则该项将分别延伸到底部或右边缘。其余同上。

voidaddWidget(QWidget *widget, int row, int column, Qt::Alignment alignment = Qt::Alignment())

将给定widget 添加到单元网格的row, column处。默认左上角位置为(0, 0) 。

对齐方式由 alignment 指定。默认对齐为 0,表示控件将填充整个单元格。

voidaddWidget(QWidget *widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment = Qt::Alignment())

此重载版本将给定widget从fromColumn、fromColumn 开始添加,跨越rowSpan行和columnSpan列。其余同上。

QRectcellRect(int row, int column) const
返回网格中row行和column列的单元格的几何形状。如果 row 或 column 位于网格之外,则返回无效的矩形。
intcolumnCount() const
返回此网格中的列数。
intcolumnMinimumWidth(int column) const
返回column列的列间距。
intcolumnStretch(int ) const
返回column列的拉伸系数。
voidgetItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan) const

返回具有给定index项的位置。

作为row和column传递的变量将随着项在布局中的位置而更新,而rowSpan和columnSpan变量将随着项目的垂直和水平跨度而更新。

inthorizontalSpacing() const
返回并排控件的水平间距。
QLayoutItem *itemAtPosition(int row, int column) const
返回布局中占用 (row, column) 单元格的项,或者如果单元格为空,则返回nullptr。
Qt::CorneroriginCorner() const
返回用于网格原点的角,即位置(0, 0)。
introwCount() const
返回此网格中的行数。
introwMinimumHeight(int row) const
返回row行设置的最小宽度。
introwStretch(int row) const
返回row行的拉伸系数。
voidsetColumnMinimumWidth(int column, int minSize)
将column列的最小宽度设置为minSize像素。
voidsetColumnStretch(int column, int stretch)

将column列的拉伸系数设置为stretch。

拉伸系数是相对于此网格中的其他列的,拉伸系数较高的列占用更多的可用空间。

第一列拉伸系数是0。默认拉伸系数为 0。如果拉伸系数为 0,并且此表中的其他列无法增长,该列仍可能会增长。

另一种方法是使用 addItem() 添加QSpacerItem增加间距。

voidsetHorizontalSpacing(int spacing)
设置并排控件的水平间距。
voidsetOriginCorner(Qt::Corner corner)
将网格的原点角,即位置 (0, 0),设置为corner。
voidsetRowMinimumHeight(int row, int minSize)
将row行的最小高度设置为minSize像素。
voidsetRowStretch(int row, int stretch)

将row行的拉伸系数设为stretch。

拉伸系数是相对于此网格中的其他行的,拉伸系数较高的行占用更多可用空间。

第一行拉伸系数是0,默认拉伸系数为 0。如果拉伸系数为 0,并且此表中的其他行无法增长,该行仍可能会增长。

voidsetVerticalSpacing(int spacing)
设置控件之间的垂直间距。
intverticalSpacing() const
返回控件之间的垂直间距。

【重实现的公有函数】

virtual intcount() const override

详见父类:

< QLayout

< QLayoutItem

virtual Qt::OrientationsexpandingDirections() const override
virtual boolhasHeightForWidth() const override
virtual intheightForWidth(int w) const override
virtual voidinvalidate() override
virtual QLayoutItem *itemAt(int index) const override
virtual QSizemaximumSize() const override
virtual intminimumHeightForWidth(int w) const override
virtual QSizeminimumSize() const override
virtual voidsetGeometry(const QRect &rect) override
virtual voidsetSpacing(int spacing) override
virtual QSizesizeHint() const override
virtual intspacing() const override
virtual QLayoutItem *takeAt(int index) override

【重新实现的受保护函数】

virtual voidaddItem(QLayoutItem *item) override实际程序中不会用此函数添加项。通常添加控件用 addWidget() ,添加布局用addLayout()。

<<< 返回上一级【QLayout类】

<<< 返回根页面

PyQt QGridLayout 类详解 摘要:QGridLayout是PyQt中强大的网格布局管理器,通过行列结构实现控件精准定位。核心功能包括添加控件(支持跨行跨列)、设置行列属性(拉伸因子/最小尺寸)、调整间距边距等,特别适合构建表单、设置界面等复杂布局。文中通过个人信息表单等完整示例,展示了如何嵌套布局、对齐控件、设置响应式拉伸等实用技巧,并总结了规划网格结构、使用组框分类等最佳实践。该布局管理器为开发结构化、自适应界面提供了高度灵活性。 阅读详情

相关推荐

【QT开发】网格布局管理器QGridLayout类详解及实战应用

QGridLayout 是 Qt 提供的一个功能强大且灵活的网格布局管理器,通过本篇文章的学习,你应该对 QGridLayout 有了全面的理解,能够在自己的项目中正确使用它。网格布局管理器在用户界面中帮助你更好地管理和安排控件的位置,有助于创建用户友好和美观的界面。

科技改变人类,技术成就未来 1263

Qt之格栅布局(QGridLayout)

简述 QGridLayout:格栅布局,也被称作网格布局(多行多列)。 栅格布局将位于其中的窗口部件放入一个网状的栅格之中。QGridLayout需要将提供给它的空间划分成的行和列,并把每个窗口部件插入并管理到正确的单元格。 栅格布局是这样工作的: 它计算了位于其中的空间,然后将它们合理的划分成若干个行(row)和列(colu...

weixin_34419321的博客 7364

Qt | QGridLayout 类(网格布局)

QGridLayout基本原理是把窗口划分为若干个单元格,每个子部件被放置于一个或多个单元格之中,各 单元格的大小可由拉伸因子和一行或列中单元格的数量来确定,若子部件的大小(由 sizeHint()确定)小于单元格,则可以设置该子部件位于单元格的什么位置(顶部、左侧、底 部等),还可设置该子部件是否可以拉伸以填满该单元格等等。

Qt历险记,专注Qt技术,三年医疗设备研发经验,1年机器视觉研发经验,半年柔性传感研发经验。 1326

[Qt 教程之Widgets模块] —— QGridLayout栅格布局

与`QBoxLayout`只能在一个方向布局不同,`QGridLayout`可以在网格中布局(垂直和水平两个方向)。

淋曦的进击手记 2万+

Android-S无线模块前瞻

WiFi - mainlane非强制 S 采用反射的方法直接加载wifiservice,直接hook在systemserver上,无编译依赖。gms可以动态替换wifi服务。 R 采用直接启动service的方式,wifiservice仍然map在systemserver上。 WiFi - 11ad接口支持 11ad被wifi联盟商业化为WIGIG,提供短距的60GHZ载波,理论速度为当前5G 11ac的6倍。市面上基本没有手机支持,需要独立的芯片支撑此功能。 传输距离为3m以内,外界d.

头铁的伦的博客 1044

【TI毫米波雷达】IWR6843AOPEVM-G与DCA1000EVM实战:从硬件连接到数据流解析

本文详细解析了TI毫米波雷达开发套件IWR6843AOPEVM-G与DCA1000EVM的硬件连接、模式配置及数据流处理全流程。针对官方手册中的常见配置错误,提供了避坑指南和实测验证的正确设置方法,包括开关配置、网络参数等关键步骤。通过mmWave Studio软件配置雷达参数,并深入解析数据采集与处理流程,帮助开发者高效实现毫米波雷达应用开发。

weixin_30653023的博客 368

QT QGridLayout网格布局控件

本文详细的介绍了QGridLayout控件的各种操作,例如:新建界面、控件布局、获取行、获取列、某行伸缩系数、某列伸缩系数、某列最小宽度、某行最小宽度、总单元格数、移除布局条目、移动布局条目、其它文章等操作。 实际开发中,一个界面上可能包含十几个控件,手动调整它们的位置既费时又费力。布局管理器可以完成两件事:自动调整控件的位置,包括控件之间的间距、对齐等;当用户调整窗口大小时,位于布局管理器内的控件也会随之调整大小,从而保持整个界面的美观。 本系列QT全面详解文章目前共有二

断点 2978

8卡H20运行DeepSeek-V3-0324性能和推理实测

最近在一台 8卡H20 机器上,先后部署了 DeepSeek-R1-AWQ (671B)和最新的 DeepSeek-V3-0324 (685B) ,测试了下性能和数学问题跑分。服务器由火山引擎提供。

weixin_53138109的博客 3365

删除QGridLayout中的Widget

准备工作1.新建一个工程,然后删除mainwindow的ui,头文件和源文件。2.新建一个主窗口,布局如下: 3.新建一个窗口作为子窗口,用于动态加入到widgetGridLayout布局中。 代码实现实现AddWidget按钮槽函数void Form::on_btnAddWidget_clicked() { childWidget *widget = new childWidget

迷惘宅猪的专栏 2万+

OTA(Over-The-Air)升级

OTA(Over-the-Air)是一种通过无线方式进行数据传输和更新的技术,通常用于电子设备(如智能手机、汽车、物联网设备等)的软件、固件或配置更新。OTA可以在设备与服务器之间进行远程传输,用户无需将设备接入电脑或进行有线操作。通过OTA,用户只需要通过Wi-Fi或移动网络连接,便能自动接收并安装最新的更新,而无需手动干预。OTA的优点是便捷和高效,能够确保设备随时保持最新状态,同时减少用户的操作负担。:如智能家居设备、路由器、汽车等硬件设备的固件更新。:确保设备上的应用保持最新版本。

weixin_50127894的博客 5063

DSP28335 ADC模块实战:从寄存器配置到精准数据采集(附代码详解)

本文详细解析DSP28335的ADC模块配置与数据采集实战,涵盖寄存器设置、采样窗口优化、中断处理及代码实现。重点解决ADC精度问题,如采样窗口不足导致数据偏差,提供完整代码示例和调试技巧,助力工程师实现精准数据采集。

kkk56的博客 864

动态刷新QGridLayout中的Widget

while(layout->count() > 0) { //TianYe-2011-11-19-删除QLayoutGrid中的Widget QWidget* widget = layout->itemAt(0)->widget(); layout->removeWidget(widget); delete widget; } layout是QGridLay

4079

基于YOLOv8的端面小目标计数解决方案: 多头检测器+小缺陷到大缺陷一网打尽的GiraffeDet+Wasserstein Distance Loss | 助力工业小目标缺陷检测

端面小目标计数部署解决方案 | 亲测在工业小目标缺陷涨点明显,原始mAP@0.5 0.936提升至0.955

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 1955

QGridLayout类详细介绍

是 PyQt5 中用于将控件按的布局管理器,支持复杂的多行多列布局,适合构建表单、仪表盘等需要精确控制控件位置的场景。

wanglaqqqq的博客 1159

PCL 提取两片点云的非重叠部分【2025最新版】

PCL 提取两片点云的非重叠部分。博客长期更新,本文最近一次更新时间为:2025年9月1日。

点云侠的博客 36万+

倒立摆的PLC控制(模型分析+ SCL源代码)

首先简单介绍下倒立摆模型,下面这幅图是MATLAB网站上的倒立摆模型,下面我们利用牛顿第二运动定律建立摆杆的运动方程。

RXXW_Dor的博客 3333

QGridLayout类及示例

将其分为行和列,并将其管理的每个小部件放入正确的单元格中。由于网格布局管理器中的组件也是会随着窗口拉伸而发生变化的,所以也是需要设置组件之间的比例系数的,与。网格布局,使用几个按钮,将他们设置为网格布局,同时设置它们的行、列比例系数(拉伸因子),以及设置它们的一些属性。系数比(拉伸因子),所以看到的按钮是按系数比的比例显示。”具体代码由新建项目时生成,无改动。程序编译运行的结果如下。不同的是网格布局管理器还需要分别。类提供了布局管理器里的一种以。个按钮,因为设置了行、列的。的方式管理界面组件。

2301_79503228的博客 230

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

布局类(08):【类】QGridLayout[官翻]

文章目录详细说明属性公共函数构造和析构属性相关增加和索引位置相关大小相关重写的公共函数重写的受保护的函数相关代码 QGridLayout 类 QGridLayout类在网格中布局小部件。 Header: #include < QGridLayout > qmake: QT += widgets Inherits: QLayout Inherited By: 详细说明 QGridLayout获取可用的空间(通过其父布局或parentWidget() ),将其划分为行

读书笔记 1380

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

深度学习工具包 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")

PyQt6/PySide6 的 QGridLayout 类

优先使用布局管理器而非绝对坐标合理设置拉伸因子实现响应式布局使用最小尺寸约束防止内容压缩定期调用update()刷新布局配合QSpacerItem实现灵活留白# 综合示例:带边栏的主界面main_layout.addWidget(sidebar, 0, 0, 2, 1) # 跨两行main_layout.setColumnStretch(1, 3) # 内容区域3倍宽度main_layout.setRowStretch(0, 3) # 主内容区3倍高度。

燃灯工作室 650

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

「QT」布局类 之 QGridLayout 网格布局类

QGridLayout是Qt框架中一个用于管理窗口部件布局的类。它将窗口或小部件划分为一个规则的网格,并将小部件放置在网格的不同位置上。QGridLayout可以自动调整小部件的大小和位置,以适应窗口的大小调整。这使得QGridLayout成为创建复杂用户界面的强大工具。QGridLayout的构造函数非常简单,可以通过默认构造函数创建一个空的网格布局,也可以通过指定父部件的构造函数创建一个与父部件关联的网格布局。QGridLayout提供了丰富的公有函数,用于添加、删除和管理小部件。

何曾参静谧的博客 1430

【Python开发技术之PyQt5精品教学】第9课--PyQt5 QGridLayout类

GridLayout类对象以行和列排列的单元格网格的形式呈现。该类包含addWidget()方法。通过指定单元格的行数和列数可以添加任何小部件。如果指定了行和列的跨度因子,可以使小部件的宽度或高度大于一个单元格。addWidget()方法有两种重载形式,如下所示−网格中的任何单元格也可以添加子布局对象。

xzs51job的专栏 551

Qt布局管理(4):网格布局(QGridLayout类)

Qt布局管理(4):网格布局(QGridLayout类)

weixin_37603532的博客 540

基本布局-QHBoxLayout类、QVBoxLayout类、QGridLayout类

(1)新建Qt Widget Application,项目名UserInfo,基类QDialog,取消创建界面; (2)打开dialog.h头文件,在头文件中声明对话框中的各个控件,添加代码#ifndef DIALOG_H #define DIALOG_H#include <QDialog> //添加头文件 #include <QLabel> #include <QLineEdit> #inclu

雨中山草 1万+

Qt:QChart绘图介绍(主要包含类:QChart,QTableWidget,QGridLayout)

Qt:QChart绘图介绍(主要包含类:QChart,QTableWidget,QGridLayout) 首先点击【打开】摁键,从excel中读入相关数据 之后点击【计算】摁键,将数据进行处理,并将部分输出到TableWidget中,部分绘制到QChart中 目录 效果展示: TableWidget绘制及数据输出: QChart相关内容(刷新,图例,绘制双曲线,自定义坐标系): QG...

qq_41605114的博客 9629

Qt horizontal line和vertical line的使用方法及在 QGridLayout 中的应用

1.horizontal line 和vertical line 的使用 horizontal line 和vertical line 实际上是由QFame类,设置相应的参数来实现的;而不是由单独的类来实现的,例如(QHorizontalLine/QVerticalLine); 1.1.控件拖拽 1.2.代码实现 QFrame *line = new QFrame()...

qq_37282105的博客 5171
上一篇: QSpacerItem类
下一篇: QList类
floatbit
博客等级 码龄24年 460粉丝 47原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值