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

使用QML的Rectangle组件的边框属性

要为这个矩形背景添加边框设计,可以使用QML的Rectangle组件的边框属性。以下是几种不同的边框设计方案:

1. 基础边框设计

background: Rectangle {width: 260height: 42color: "#001c2f"border {width: 1  // 边框宽度color: "#1e90ff"  // 边框颜色(道奇蓝)}radius: 4  // 圆角半径
}

2. 渐变边框设计

background: Rectangle {width: 260height: 42color: "#001c2f"radius: 4// 内层边框Rectangle {anchors.fill: parentanchors.margins: 1color: "transparent"border {width: 1color: "#1e90ff"}radius: 3  // 比外层小1}
}

3. 发光边框效果

background: Rectangle {width: 260height: 42color: "#001c2f"radius: 4// 发光效果layer.enabled: truelayer.effect: Glow {radius: 8samples: 16color: "#1e90ff"transparentBorder: true}
}

4. 立体边框设计

background: Rectangle {width: 260height: 42color: "#001c2f"radius: 4// 上/左边框(亮色)Rectangle {width: parent.widthheight: 1color: "#3a9eff"}Rectangle {width: 1height: parent.heightcolor: "#3a9eff"}// 下/右边框(暗色)Rectangle {anchors.bottom: parent.bottomwidth: parent.widthheight: 1color: "#005a9c"}Rectangle {anchors.right: parent.rightwidth: 1height: parent.heightcolor: "#005a9c"}
}

5. 虚线边框设计

background: Rectangle {width: 260height: 42color: "#001c2f"// 虚线边框(需要Canvas绘制)Canvas {anchors.fill: parentonPaint: {var ctx = getContext("2d")ctx.strokeStyle = "#1e90ff"ctx.lineWidth = 1ctx.setLineDash([3, 3])  // 3像素实线,3像素空白ctx.strokeRect(0, 0, width, height)}}
}

6. 复合边框设计(推荐)

background: Rectangle {width: 260height: 42color: "#001c2f"radius: 4// 外边框border {width: 1color: "#0a3d6b"}// 内边框Rectangle {anchors.fill: parentanchors.margins: 2color: "transparent"border {width: 1color: "#1e90ff"}radius: 2}
}

设计建议:

  1. 颜色搭配:深色背景(“#001c2f”)适合搭配亮蓝色系边框(“#1e90ff”)
  2. 圆角处理radius属性可以让边框更柔和
  3. 性能考虑:简单边框性能最好,发光效果最耗资源
  4. 交互反馈:可以添加状态变化:
    border.color: mouseArea.containsMouse ? "#3a9eff" : "#1e90ff"
    

选择哪种方案取决于您的具体设计需求和性能要求。复合边框设计(方案6)在视觉效果和性能之间取得了较好的平衡。

http://www.xdnf.cn/news/1369873.html

相关文章:

  • HMM简单拓展-HSMM与高阶HMM
  • C/C++ 数据结构 —— 树(2)
  • nginx-负载均衡
  • C++工程实战入门笔记4-函数(一)
  • WeakAuras Lua Script ICC (BarneyICC) Simplified Chinese [Mini]
  • 深入了解linux系统—— 线程互斥
  • ArcGIS学习-11 实战-商场选址
  • 洛谷 P12332 题解
  • 如何利用ArcGIS探究环境与生态因子对水体、土壤、大气污染物等影响实践技术
  • pytorch_grad_cam 库学习笔记—— Ablation-CAM 算法的基类 AblationCAM 和 AblationLayer
  • 如何避免频繁切换npm源
  • pytorch-利用letnet5框架深度学习手写数字识别
  • Vue2(七):配置脚手架、render函数、ref属性、props配置项、mixin(混入)、插件、scoped样式
  • 深入解析交换机端口安全:Sticky MAC的工作原理与应用实践
  • 机器视觉学习-day03-灰度化实验-二值化和自适应二值化
  • 【C++】智能指针底层原理:引用计数与资源管理机制
  • 深度学习篇---LeNet-5网络结构
  • 病理软件Cellprofiler使用教程
  • vue2 和 vue3 生命周期的区别
  • 一篇文章拆解Java主流垃圾回收器及其调优方法。
  • LeetCode-22day:多维动态规划
  • 代码随想录Day62:图论(Floyd 算法精讲、A * 算法精讲、最短路算法总结、图论总结)
  • vue2和vue3的对比
  • TensorFlow 深度学习:使用 feature_column 训练心脏病分类模型
  • Day3--HOT100--42. 接雨水,3. 无重复字符的最长子串,438. 找到字符串中所有字母异位词
  • CentOS 7 服务器初始化:从 0 到 1 的安全高效配置指南
  • 肌肉力量训练
  • 木马免杀工具使用
  • 产品经理操作手册(3)——产品需求文档
  • 全链路营销增长引擎闭门会北京站开启倒计时,解码营销破局之道