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

QML学习笔记(三十一)QML的Flow定位器

前言

本节将介绍一个名叫Flow的定位器,如含义所言,这种布局就像会流动一样,会根据组件数量、尺寸、父容器的大小自动适应布局。

一、代码演示

因为比较简单,我们直接看代码:

Window {visible: truewidth: 640height: 480title: qsTr("QmlFlow")Flow{anchors.fill: parentanchors.margins: 4spacing: 10Rectangle{id: topLeftRectIdwidth: 100height: widthcolor: "magenta"Text {anchors.centerIn: parenttext: "1"font.pointSize: 20}}Rectangle{id: topCenterRectIdwidth: 100height: widthcolor: "yellowgreen"Text {anchors.centerIn: parenttext: "2"font.pointSize: 20}}Rectangle{id: topRightRectIdwidth: 100height: widthcolor: "dodgerblue"Text {anchors.centerIn: parenttext: "3"font.pointSize: 20}}Rectangle{id: centerLeftRectIdwidth: 100height: widthcolor: "red"Text {anchors.centerIn: parenttext: "4"font.pointSize: 20}}Rectangle{id: centerCenterRectIdwidth: 100height: widthcolor: "green"Text {anchors.centerIn: parenttext: "5"font.pointSize: 20}}Rectangle{id: centerRightRectIdwidth: 100height: widthcolor: "blue"Text {anchors.centerIn: parenttext: "6"font.pointSize: 20}}Rectangle{id: bottomLeftRectIdwidth: 100height: widthcolor: "royalblue"Text {anchors.centerIn: parenttext: "7"font.pointSize: 20}}Rectangle{id: bottomCenterRectIdwidth: 100height: widthcolor: "yellow"Text {anchors.centerIn: parenttext: "8"font.pointSize: 20}}Rectangle{id: bottomRightRectIdwidth: 100height: widthcolor: "pink"Text {anchors.centerIn: parenttext: "9"font.pointSize: 20}}}
}

代码很长,但也只是九宫格矩形而已。
我们聚焦在这几句:

    Flow{anchors.fill: parentanchors.margins: 4spacing: 10
//...}

它的使用非常简单,甚至不需要设置什么复杂的属性,这里只简单给了间距。
当然,Flow生效的前提是每一个组件都已经写了固定尺寸。
我们运行代码看看:
在这里插入图片描述
拖拽一下窗口:
在这里插入图片描述
在这里插入图片描述
自动换行的效果非常丝滑,且在某种场合当中非常好用。
比如我们需要自己手搓一个文件管理器,需要在一个窗口内部实现多文件的排布,此时就可以用这种方式,就比较灵活了。
另外就是还有一个换行方向的问题,我们可以指定:

flow:Flow.TopToBottom

效果就会变成这样:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
如果再加上:

layoutDirection: Qt.RightToLeft

在这里插入图片描述

二、总结

Flow的定位方式虽然没那么常用,但在某种场合下可能是一种更优的选择。至此,我们应该已经掌握了比较丰富的定位和布局方式了。

http://www.dtcms.com/a/466962.html

相关文章:

  • 国防教育网站建设说明书苏州协会网站建设
  • Prompt-tuning、Prefix-tuning、P-tuning/v2
  • 青岛胶南市城乡建设局网站页面效果图
  • vscode连接wsl 连接本地项目
  • 掌握定时器基于GD32F407VE的天空星的配置
  • 补充:计算点到原点的距离。(new)
  • 北京网站建设 专业10年郑州艾特网站建设公司
  • 陕西做网站的公司在哪江苏建设行业证书编号查询网站
  • 元服务发布准备工作
  • 【2025-系统规划与管理师】第七章:网络环境规划
  • 固态硬盘保护器Romex Software
  • 如室设计网站东莞房价多少
  • 创建网站超市百度找不到 网站
  • 超参数优化利器:GridSearchCV 详解与实战指南
  • 网站建设合同需要注意什么创意赣州网站建设
  • 从 Wonderware 到 TDengine:大理卷烟厂的国产化转型之路
  • Redis-Bitmaps、HyperLogLog、GEO类型
  • 一级a做爰片i网站商城网站前期推广
  • Golang的结构体和反射
  • 网站点击量软件古腾堡布局的网站
  • 网站title优化手机网页页面设计模板
  • 湛江正规网站制作方案网站建设五项基本原则
  • 【Vue】——路由
  • 160 国际英文网站app开发公司哪里好
  • 企业网站优化哪家好陕西住房与城乡建设部网站
  • 小模型大智慧:新一代轻量化语言模型全解析
  • 网站首页背景代码wordpress幻灯片不显示
  • 37.2多点电容触摸屏实验(详细代码)_csdn
  • 了解学习MySQL数据库基础
  • 做网站怎么选服务器服务器网站怎么做