QML 自定义矩形框Rectangle,实现四个边框自定义大小

一、自定义矩形

效果图

边框大小为:左2 上2 右5 下10

简单来说,就是定义两个矩形,一个在外边一个在内部;

再通过设置他们的边距,即可设置相应的边框宽度;

1.编码

新建空的qml文件

MyRectangle.qml

import QtQuick 2.0Rectangle {id: borderRectproperty int innerTopMargin: 0        // 上边距property int innerBottomMargin: 0     // 下边距property int innerLeftMargin: 0       // 左边距property int innerRightMargin: 0      // 右边距property string innerColor: "white"   // 矩形颜色property string bodercolor: "black"   // 边框颜色width: 100height: 50color: innerColorRectangle {id: innerRectcolor: bodercoloranchors.fill: parent    // 填充满父类anchors.topMargin: innerTopMarginanchors.bottomMargin: innerBottomMarginanchors.leftMargin: innerLeftMarginanchors.rightMargin: innerRightMargin}
}

2.使用

// 自定义矩形                                                 
MyRectangle {                                               height: 100                                             width: 200                                              innerTopMargin: 2       // 顶部边框大小                       innerBottomMargin: 10   // 底部                           innerLeftMargin: 2      // 左边                           innerRightMargin: 5     // 右边                           bodercolor: "black"    // 边框颜色                         innerColor: "yellow"     // 矩形颜色                          // 居中                                                   anchors.verticalCenter: parent.verticalCenter           anchors.horizontalCenter: parent.horizontalCenter       //anchors.centerIn: parent                              
}                                                  

二、九宫格

可以使用矩形的相对位置,去设置一个九宫格出来;

即 以下这四个属性

anchors.top        anchors.left        anchors.right        anchors.bottom

源码如下:

import QtQuick 2.9
import QtQuick.Window 2.2import QtQuick.Controls 2.2Window {visible: truewidth: 640height: 480title: qsTr("Hello World")color: "white"MyRectangle {id: rect1x: 50y: 50height: 50width: 100innerTopMargin: 2       // 顶部边框大小innerBottomMargin: 10   // 底部innerLeftMargin: 2      // 左边innerRightMargin: 5     // 右边bodercolor: "black"    // 边框颜色innerColor: "yellow"     // 矩形颜色}MyRectangle {id: rect2y: rect1.ywidth: rect1.widthheight: rect1.heightinnerTopMargin: rect1.innerTopMargininnerBottomMargin: rect1.innerBottomMargininnerLeftMargin: rect1.innerLeftMargininnerRightMargin: rect1.innerRightMarginbodercolor: rect1.bodercolorinnerColor: rect1.innerColoranchors.left: rect1.rightanchors.leftMargin: 5}MyRectangle {id: rect3y: rect1.ywidth: rect1.widthheight: rect1.heightinnerTopMargin: rect1.innerTopMargininnerBottomMargin: rect1.innerBottomMargininnerLeftMargin: rect1.innerLeftMargininnerRightMargin: rect1.innerRightMarginbodercolor: rect1.bodercolorinnerColor: rect1.innerColoranchors.left: rect2.rightanchors.leftMargin: 5}MyRectangle {id: rect4x: rect1.xy: rect1.ywidth: rect1.widthheight: rect1.heightinnerTopMargin: rect1.innerTopMargininnerBottomMargin: rect1.innerBottomMargininnerLeftMargin: rect1.innerLeftMargininnerRightMargin: rect1.innerRightMarginbodercolor: rect1.bodercolorinnerColor: rect1.innerColoranchors.top: rect1.bottomanchors.topMargin: 5}MyRectangle {id: rect5width: rect1.widthheight: rect1.heightinnerTopMargin: rect1.innerTopMargininnerBottomMargin: rect1.innerBottomMargininnerLeftMargin: rect1.innerLeftMargininnerRightMargin: rect1.innerRightMarginbodercolor: rect1.bodercolorinnerColor: rect1.innerColoranchors.top: rect2.bottomanchors.left: rect4.rightanchors.leftMargin: 5anchors.topMargin: 5}MyRectangle {id: rect6width: rect1.widthheight: rect1.heightinnerTopMargin: rect1.innerTopMargininnerBottomMargin: rect1.innerBottomMargininnerLeftMargin: rect1.innerLeftMargininnerRightMargin: rect1.innerRightMarginbodercolor: rect1.bodercolorinnerColor: rect1.innerColoranchors.top: rect3.bottomanchors.left: rect5.rightanchors.leftMargin: 5anchors.topMargin: 5}MyRectangle {id: rect7x: rect1.xy: rect1.ywidth: rect1.widthheight: rect1.heightinnerTopMargin: rect1.innerTopMargininnerBottomMargin: rect1.innerBottomMargininnerLeftMargin: rect1.innerLeftMargininnerRightMargin: rect1.innerRightMarginbodercolor: rect1.bodercolorinnerColor: rect1.innerColoranchors.top: rect4.bottomanchors.topMargin: 5}MyRectangle {id: rect8width: rect1.widthheight: rect1.heightinnerTopMargin: rect1.innerTopMargininnerBottomMargin: rect1.innerBottomMargininnerLeftMargin: rect1.innerLeftMargininnerRightMargin: rect1.innerRightMarginbodercolor: rect1.bodercolorinnerColor: rect1.innerColoranchors.top: rect5.bottomanchors.left: rect7.rightanchors.leftMargin: 5anchors.topMargin: 5}MyRectangle {id: rect9width: rect1.widthheight: rect1.heightinnerTopMargin: rect1.innerTopMargininnerBottomMargin: rect1.innerBottomMargininnerLeftMargin: rect1.innerLeftMargininnerRightMargin: rect1.innerRightMarginbodercolor: rect1.bodercolorinnerColor: rect1.innerColoranchors.top: rect6.bottomanchors.left: rect8.rightanchors.leftMargin: 5anchors.topMargin: 5}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/20264.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

筛选相同项

# import os # import pandas as pd# # 文件路径,根据实际情况修改 # file_path_1 rC:\Users\Administrator\Desktop\python\文件1.xlsx # file_path_2 rC:\Users\Administrator\Desktop\python\文件2.xlsximport os import pandas as pd# 获取当前脚本所在的目录…

MVTEC数据集笔记

前言 网上的博客只有从论文里摘出的介绍,没有数据集文件详细的样子,下载数据集之后,对数据集具体的构成做一个补充的笔记。 下载链接:https://ai-studio-online.bj.bcebos.com/v1/7d4a3cf558254bbaaf4778ea336cb14ed8bbb96a7f2a…

Bom详解和Dom详解

Javascript的数据类型 1.BOM(浏览器对象模型)1.1window对象(1)全局作用域:(2)窗口属性:(3)弹窗和对话框:(4)定时器:(5)导航和历史:(6)打开和关闭窗口: 1.2navigator对象(1)浏览器信息属性:(2)浏…

Android 虚拟机与ClassLoader类加载笔记

1 Android虚拟机 在介绍Android的虚拟机之前,我们先来看一下JVM虚拟机之下,我们的class文件的字节码指令的Demo: public class Demo {public static void test() {int a 1;int b 2;int c a b;} } 将Demo.class文件使用命令&#xff1a…

STM32 HAL库USART串口DMA IDLE中断编程:避坑指南

HAL_UART_Receive接收最容易丢数据了,STM32 HAL库UART查询方式实例 可以考虑用中断来实现,但是HAL_UART_Receive_IT还不能直接用,容易数据丢失,实际工作中不会这样用,STM32 HAL库USART串口中断编程:演示数据丢失, 需要在此基础优化一下. STM32F103 HAL库USART串口…

NBT群落物种级丰度鉴定新方法sylph

文章目录 简介为什么选择Sylph?Sylph的工作原理 Install使用解析成gtdb格式sylph 能做什么?sylph 不能做什么?ANI定义如何使用 sylph-utils 生成包含分类信息的配置文件耗时:66个样本耗时1h 转成easymicroplot可用数据 简介 Sylp…

VLM 系列——Qwen2.5 VL——论文解读——前瞻(源码解读)

引言 20250212苹果突然被爆将与阿里巴巴合作为中国 iPhone 用户开发人工智能功能。苹果从 2023 年就已经开始测试各类中国头部 AI 大厂开发的 AI 模型。去年,原本选定百度作为主要合作伙伴,但双方的合作并不顺利,百度为“Apple Intelligence”…

DeepSeek R1原理

文章目录 DeepSeek R1原理强化学习介绍Policy ModelCritic ModelReward Model三者关系智能体包含的内容环境包含的内容 知识蒸馏简介数据蒸馏Logits 蒸馏特征蒸馏 训练流程DeepSeek-R1-Zero 训练策略与价值设计奖励方式训练模板**实验观察到模型自我进化**缺点 DeepSeek-R1 训练…

如何使用DeepSeek + PlantUML/Mermaid 生成专业图表

目录 一、工具简介 1.1 DeepSeek简介 1.2 PlantUML简介 1.3 Mermaid在线工具简介 二、在DeepSeek中生成Mermaid语法 2.1 编写提示词 2.2 示例输出 2.3 访问Mermaid在线编辑器 三、在DeepSeek中生成PlantUML语法 3.1 编写提示词 3.2 示例输出 3.3 访问PlantUML在线编…

开源多商户商城源码最新版_适配微信小程序+H5+APP+PC多端

在数字化时代,电子商务已经成为各行业不可或缺的一部分,开源多商户商城源码为中小企业和个人开发者提供了快速搭建和定制电商平台的利器。分享一款最新版的开源多商户商城源码,它能够适配微信小程序、H5、APP和PC等多个端口,满足商…

PHP基础部分

但凡是和输入、写入相关的一定要预防别人植入恶意代码! HTML部分 语句格式 <br> <hr> 分割符 <p>插入一行 按住shift 输入! 然后按回车可快速输入html代码(VsCode需要先安装live server插件) html:<h1>标题 数字越大越往后</h1> <p…

短视频矩阵碰一碰发视频源码技术开发,支持OEM

在短视频矩阵碰一碰发视频的技术开发中&#xff0c;前端设计是直接面向用户的关键部分&#xff0c;它不仅决定了用户体验的好坏&#xff0c;还对整个系统的可用性和吸引力起着重要作用。本文将深入探讨在这一技术开发中前端设计的要点、流程与关键技术。 一、前端设计的整体架构…

大模型 + cursor应用案例

cursor 介绍 cursor是一个集成了GPT4、Claude 3.5等先进LLM的类vscode的编译器&#xff0c;可以理解为在vscode中集成了AI辅助编程助手&#xff0c;从下图中的页面可以看出cursor的布局和vscode基本一致&#xff0c;并且cursor的使用操作也和vscode一致&#xff0c;包括extens…

深入浅出CSS复合选择器:掌控元素关系与层级选择

目录 前言 一、子代选择器&#xff08;Descendant Selector&#xff09; 1. 什么是子代选择器&#xff1f; 2. 基本语法 3. 示例 4. 注意事项 二、直接子元素选择器&#xff08;Child Selector&#xff09; 1. 什么是直接子元素选择器&#xff1f; 2. 基本语法 3. 示例…

CSRF 漏洞原理演示 基本绕过(同源 异源) 配合XSSToken值校验复用删除

前言 CSRF的基本原理 就是 举例 我们伪造一个支付宝的转账请求&#xff08;抓包获取的&#xff09;&#xff0c;受害者 &#xff1a; 正好登录着支付宝&#xff08;后台&#xff09;的 同时点击了我们伪造的&#xff08;包含恶意请求&#xff09;网址 从而导致先我们进行转…

外包干了3天,技术退步太明显了。。。

先说一下自己的情况&#xff0c;本科生生&#xff0c;21年通过校招进入武汉某软件公司&#xff0c;干了差不多3年的功能测试&#xff0c;感觉自己不能够在这样下去了&#xff0c;长时间呆在一个舒适的环境会让一个人堕落!而我已经在一个企业干了3年的功能测试&#xff0c;已经让…

HomeAssistant 发现MQTT设备(温度,湿度,开关)

要通过 MQTT 将温度、湿度数据以及一个灯的开关状态传输到 Home Assistant 并实现设备自动发现&#xff0c;可以按照以下步骤操作&#xff1a; 1.前期准备工作 安装MQTT服务器(EMQX)配置好(可以在HA加载项中安装,也可以在NAS上Docker安装) HA的集成中安装MQTT,并且连接上(EM…

【stm32】DAC实验(stm32f4hal库)

一、DAC简介 1、DAC 数字到模拟转换器&#xff08;DAC&#xff09;是一种电子设备&#xff0c;用于将数字信号转换为模拟信号。它通常用于将数字数据转换为模拟信号&#xff0c;以便在模拟电路中进行处理。DAC在许多领域都有广泛的应用&#xff0c;如音频设备、通信系统、仪器…

云计算架构学习之Ansible-playbook实战、Ansible-流程控制、Ansible-字典循环-roles角色

一、Ansible-playbook实战 1.Ansible-playbook安装软件 bash #编写yml [rootansible ansible]# cat wget.yml - hosts: backup tasks: - name: Install wget yum: name: wget state: present #检查playbook的语法 [rootansible ansible]…

前端工程化的具体实现细节

&#x1f90d; 前端开发工程师、技术日更博主、已过CET6 &#x1f368; 阿珊和她的猫_CSDN博客专家、23年度博客之星前端领域TOP1 &#x1f560; 牛客高级专题作者、打造专栏《前端面试必备》 、《2024面试高频手撕题》 &#x1f35a; 蓝桥云课签约作者、上架课程《Vue.js 和 E…