QML之anchors锚布局

article/2025/11/5 14:49:00
QML的布局方式一般采用两种,一种就是直接设置,X与Y坐标的值。一种是采用相对位置布局,anchors锚布局。使用锚布局的能够使界面更紧凑,更有整体化。我个人相对比较喜欢使用锚布局,选取一个最合适的参考点,其他点对它采用锚布局。


anchors.baseline : AnchorLine
anchors.baselineOffset : real
anchors.bottom : AnchorLine
anchors.bottomMargin : real
anchors.centerIn : Item
anchors.fill : Item
anchors.horizontalCenter : AnchorLine
anchors.horizontalCenterOffset : real
anchors.left : AnchorLine
anchors.leftMargin : real
anchors.margins : real
anchors.mirrored : bool
anchors.right : AnchorLine
anchors.rightMargin : real
anchors.top : AnchorLine
anchors.topMargin : real

anchors.verticalCenter : AnchorLine

anchors.verticalCenterOffset : real

Rectangle{
       id:xiaohuang
       height: 80
       width: 80
       color: "yellow"
       radius: 5
       anchors.centerIn: parent //锚定位在父项的中间
       //anchors.fill: parent  //填充满父项,
       Text {
           anchors.centerIn: parent
           font.pixelSize: 30
           text: qsTr("小黄")
       }
   }
 
   Rectangle{
       id:xiaohong
       height: 80
       width: 80
       color: "red"
       radius: 5
       anchors.right: xiaohuang.left //本项的右边对齐于 xiaohuang的左边,
       anchors.rightMargin: 50 //右边缘的距离,距离为0时可以理解成边缘线公用
       //上面两条语句相当决定xiaohong的X左边
       //注意的是同时使用x,y坐标和锚布局,x,y坐标布局失效,有限与锚布局
       anchors.verticalCenter:  xiaohuang.verticalCenter //垂直线中心的定位
       anchors.verticalCenterOffset: 0 //垂直线中心的偏移
       //上面两句代码相当决定于Y坐标
       Text {
           anchors.centerIn: parent
           font.pixelSize: 30
           text: qsTr("小红")
       }
   }
 
   Rectangle{
       id:xiaolv
       height: 80
       width: 80
       color: "green"
       radius: 5
       anchors.left: xiaohuang.right
       anchors.leftMargin: 50
       //anchors.margins: 20 //所有进行边缘对齐的偏移量,优先级比上行低
       anchors.verticalCenter:  xiaohuang.verticalCenter
       anchors.verticalCenterOffset: 0
       Text {
           anchors.centerIn: parent
           font.pixelSize: 30
           text: qsTr("小绿")
       }
   }
 
   Rectangle{
       id:xiaoqing
       height: 80
       width: 80
       color: "cyan"
       radius: 5
       anchors.bottom: xiaohuang.top //本项的低端与xiaohuang和小黄的顶端对齐
       anchors.bottomMargin: 50
       //上面两行决定了Y坐标
       anchors.horizontalCenter: xiaohuang.horizontalCenter//水平线中心的定位
       anchors.horizontalCenterOffset: 0 //水平中心的偏移量
       //上面两行代码决定了X坐标的值
       Text {
           anchors.centerIn: parent
           font.pixelSize: 30
           text: qsTr("小青")
       }
   }
 
   Rectangle{
       id:xiaolan
       height: 80
       width: 80
       color: "blue"
       radius: 5
       anchors.top: xiaohuang.bottom
       anchors.topMargin: 50
       anchors.horizontalCenter: xiaohuang.horizontalCenter
       anchors.horizontalCenterOffset: 0
       Text {
           //anchors.centerIn: parent
           anchors.baseline: parent.baseline //底线等于(对齐)父的顶线
           anchors.baselineOffset: 20 //偏移量
           font.pixelSize: 30
           text: qsTr("小蓝")
           color: "red"
       }
   }




http://chatgpt.dhexx.cn/article/52ehXggj.shtml

相关文章

YOLOV5源代码学习之check_anchors()函数

该函数主要在train.py中调用 为了方便直观的阅读代码,对代码中的变量值进行了输出 def check_anchors(dataset, model, thr4.0, imgsz640):# Check anchor fit to data, recompute if necessaryprefix colorstr(autoanchor: )print(f\n{prefix}Analyzing anchors.…

QML入门教程(3): anchors的用法

QML的布局方法是anchors,锚。 例如界面上四个按钮,可以用绝对坐标 (x, y) 设置他们的位置, 代码如下: import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 2.5Window {visible: truewidth: 320height: 480title: qsTr("Hello World")co…

目标检测2——借Detectron2源码理解Anchors与RPN

文章目录 1.Regionn Proposal Network背景2.Regionn Proposal Network的结构3.Anchors4.Regionn Proposal Network的训练参考资料 欢迎访问个人网络日志🌹🌹知行空间🌹🌹 1.Regionn Proposal Network背景 RPN,Region …

QML基础:锚anchors

正文 除了传统的Grid、Row和Column外,Qt Quick还提供了一种使用锚点的方法来布局。可以将每个元素视为具有7条不可见的“锚定线”的集合:left、horizontalCenter、right、top、verticalCenter、baseline和bottom。 baseline(上图未展示)对应于文本所在的虚线。对于没有文…

细说目标检测中的Anchors

本文转载自AI公园。 作者:Raghul Asokan 编译:ronghuaiyang 导读 给大家再次解释一下Anchors在物体检测中的作用。 今天,我将讨论在物体检测器中引入的一个优雅的概念 —— Anchors,它是如何帮助检测图像中的物体,以及…

anchors布局

anchors布局 import QtQuick 2.2 import QtQuick.Window 2.2 Window {visible: truewidth: 640height: 480title: qsTr("Hello World")Rectangle {width: 300;height: 200;color: "blue";Rectangle {id: rectl;anchors.left: parent.left;anchors.leftMar…

PDU Session Anchors

在同一时刻,UE可以建立多条到同一个DN或不同DN的PDU会话;建立到同一个DN的多个PDU会话时,通过不同的UPF;每条PDU会话对应的SMF可以不同。 为了支持到DN的可选择路由功能或支持SSC mode 3模式,SMF可以控制PDU session的…

kmeans++聚类生成anchors

kmeans聚类生成anchors 说明 使用yolo系列通常需要通过kmeans聚类算法生成anchors, 但kmeans算法本身具有一定的局限性,聚类结果容易受初始值选取影响。 因此通过改进原kmeans_for_anchors.py实现 kmeans聚类生成anchors。具体实现如下: i…

anchors如何获得_Yolov3通过k-means聚类得到自己数据的anchors

本文代码参考: https://github.com/lars76/kmeans-anchor-boxes Yolov3中默认的9个anchors是作者通过对voc数据聚类得到的。 anchors 10,14, 23,27, 37,58, 81,82, 135,169, 344,319 不过,当我们训练自己的数据时,如果也采用默认的anchors,可…

Unity 锚点 Anchors

锚点介绍 锚点是Rect Transform组件中的属性,用于描述当前物体相对于父物体的对齐方式。 选中一个UI元素,就会显示其父物体的矩形框以及相对于父物体的锚点。 锚点只能位于父物体的矩形框之内。 锚点表现为四个相对出现的小三角形, 它们时而…

QML anchors 锚布局

锚布局 锚布局有7种锚线 anchors.leftanchors.rightanchors.topanchors.bottomanchors.horizontalCenteranchors.verticalCenteranchors.baseline 5种锚边距 anchors.leftMarginanchors.rightMarginanchors.topMarginanchors.bottomMarginanchors.margins 3种锚偏移 anchor…

anchors生成

关于修改anchor anchor与图片的输入分辨率有关系。 You should use this repository to get anchors: https://github.com/AlexeyAB/darknet By using this command for Yolo v3 (or v2): ./darknet detector calc_anchors data/hand.data -num_of_clusters 9 -width 720 -he…

使用k-means聚类anchors

在之前讲yolo理论基础知识时有提到过,从yolov2开始使用的anchors都是通过聚类得到的。如果想了解更多yolo相关的知识可以看看我在bilibili上录得视频:https://www.bilibili.com/video/BV1yi4y1g7ro 今天补下之前没有细讲的聚类anchors相关知识&#xff…

细说物体检测中的Anchors

点击上方“AI公园”,关注公众号,选择加“星标“或“置顶” 作者:Raghul Asokan 编译:ronghuaiyang 导读 给大家再次解释一下Anchors在物体检测中的作用。 今天,我将讨论在物体检测器中引入的一个优雅的概念 —— Ancho…

带图讲解,深度学习YOLO里面的anchors的进阶理解

如果有了解过yolo网络,那肯定也听说过anchors,当然anchors这个概念布置在YOLO里面才有,在其他的目标检测中也存在anchors这个概念。对于anchors计算的一些公式这篇文章就不进行讲解了,这篇文章主要是讲在训练网络模型过程中anchor…

Linux终端的网易云音乐——musicbox

网易云音乐是听歌的不错的选择,如果能够在命令行听歌就更cool了。特来推荐musicbox。 网易云音乐的musicbox是网易云音乐命令行版本,这款命令行的客户端使用 Python 构建,以 mpg123 作为播放后端。提供了很多使用的功能,如&#x…

MusicStore-2

1.按照MusicStore-1步骤创建mvc项目,并初始化数据库 2.修改HomeController using Chapter8.Models; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc;namespace Chapter8.Controllers {public class…

音乐i网站

开发工具(eclipse/idea/vscode等): 数据库(sqlite/mysql/sqlserver等): 功能模块(请用文字描述,至少200字) :

musicbox(暂停/启动,停止,下一曲上一首)

主界面 按下开始 按下暂停 按下停止 下一首 上一首 代码 activity_main.xml <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas.android.com/apk/res/android"android:orientation"vertical&…

node-webkit-MusicBox 基于nwjs ,html5 ,制作的音乐盒子

太长&#xff1f;单击目录直接去看最终效果&#xff0c;在最下边 文件下载地址&#xff1a;http://download.csdn.net/detail/u013934914/9180053 1.思路&#xff08;简单设想&#xff09; index.html 实现 对页面的显示&#xff0c;并调用绑定ymusic.js中的方法 需要&…