Qt Quick Qml-Rectangle案例

news2024/9/23 13:27:04

Qt Quick - Qml

1.Rectangle

在这里插入图片描述

//组件 IShadow.qml
import QtQuick
import QtQuick.Controls

Item {
    id:root
    anchors.fill: parent
    anchors.margins: -4
    property color color: "#999999"

    property int radius: 4

    Rectangle{
        width: root.width
        height: root.height
        anchors.centerIn: parent
        color: "#00000000"
        opacity: 0.02
        border.width: 1
        radius: root.radius
        border.color: root.color
    }

    Rectangle{
        width: root.width - 2
        height: root.height - 2
        anchors.centerIn: parent
        color: "#00000000"
        opacity: 0.04
        border.width: 1
        radius: root.radius
        border.color: root.color
    }
    Rectangle{
        width: root.width - 4
        height: root.height - 4
        anchors.centerIn: parent
        color: "#00000000"
        opacity: 0.06
        border.width: 1
        radius: root.radius
        border.color: root.color
    }

    Rectangle{
        width: root.width - 6
        height: root.height - 6
        anchors.centerIn: parent
        color: "#00000000"
        opacity: 0.08
        border.width: 1
        radius: root.radius
        border.color: root.color
    }

    Rectangle{
        width: root.width - 8
        height: root.height - 8
        anchors.centerIn: parent
        opacity: 0.1
        radius: root.radius
        color: "#00000000"
        border.width: 1
        border.color: root.color
    }

}
//组件 IRectangle.qml
import QtQuick
import QtQuick.Controls
import Qt5Compat.GraphicalEffects

Item {
    id:root
    property var radius:[0,0,0,0]
    property color color : "#FFFFFF"
    property bool shadow: true
    default property alias contentItem: container.data

    Rectangle{
        id:container
        width: root.width
        height: root.height
        opacity: 0
        color:root.color
    }

    IShadow{
        anchors.fill: container
        radius: root.radius[0]
        visible: {
            if(root.radius[0] === root.radius[1] && root.radius[0] === root.radius[2] && root.radius[0] === root.radius[3] && root.shadow){
                return true
            }
            return false
        }
    }

    Canvas {
        id: canvas
        anchors.fill: parent
        visible: false
        onPaint: {
            var ctx = getContext("2d");
            var x = 0;
            var y = 0;
            var w = root.width;
            var h = root.height;
            ctx.setTransform(1, 0, 0, 1, 0, 0);
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            ctx.save();
            ctx.beginPath();
            ctx.moveTo(x + radius[0], y);
            ctx.lineTo(x + w - radius[1], y);
            ctx.arcTo(x + w, y, x + w, y + radius[1], radius[1]);
            ctx.lineTo(x + w, y + h - radius[2]);
            ctx.arcTo(x + w, y + h, x + w - radius[2], y + h, radius[2]);
            ctx.lineTo(x + radius[3], y + h);
            ctx.arcTo(x, y + h, x, y + h - radius[3], radius[3]);
            ctx.lineTo(x, y + radius[0]);
            ctx.arcTo(x, y, x + radius[0], y, radius[0]);
            ctx.closePath();
            ctx.fillStyle = root.color;
            ctx.fill();
            ctx.restore();
        }
    }

    OpacityMask {
        anchors.fill: container
        source: container
        maskSource: canvas
    }

}
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("IRectangle")
    //color: Qt.rgba(226/255,229/255,234/255,1)


    ColumnLayout {
        anchors.centerIn: parent
        Item {
            width: 320
            height: 60
            RowLayout {
                anchors.centerIn: parent
                spacing: 15
                IRectangle {
                    width: 50
                    height: 50
                    color: "#744da9"
                    radius:[0,0,0,0]
                }
                IRectangle {
                    width: 50
                    height: 50
                    color: "#379039"
                    radius:[15,0,0,0]
                }
                IRectangle {
                    width: 50
                    height: 50
                    color: "#445d79"
                    radius:[15,0,15,0]
                }
                IRectangle {
                    width: 50
                    height: 50
                    color: "#9422a2"
                    radius:[15,15,15,0]
                }
                IRectangle {
                    width: 50
                    height: 50
                    color: "#ffeb3b"
                    radius:[15,15,15,15]
                }
            }
        }
        Item {
            width: 320
            height: 60
            RowLayout {
                anchors.centerIn: parent
                spacing: 15
                IRectangle {
                    width: 50
                    height: 50
                    radius:[0,0,0,0]
                    Image {
                        anchors.fill: parent
                        source: "svg/avatar_1.svg"
                    }
                }
                IRectangle {
                    width: 50
                    height: 50
                    radius:[15,0,0,0]
                    Image {
                        anchors.fill: parent
                        source: "svg/avatar_2.svg"
                    }
                }
                IRectangle {
                    width: 50
                    height: 50
                    radius:[15,0,15,0]
                    Image {
                        anchors.fill: parent
                        source: "svg/avatar_3.svg"
                    }
                }
                IRectangle {
                    width: 50
                    height: 50
                    radius:[15,15,15,0]
                    Image {
                        anchors.fill: parent
                        source: "svg/avatar_4.svg"
                    }
                }
                IRectangle {
                    width: 50
                    height: 50
                    radius:[15,15,15,15]
                    Image {
                        anchors.fill: parent
                        source: "svg/avatar_5.svg"
                    }
                }

            }

        }
    }

}

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

原型图都可以用什么软件做?分享这9款给你

设计师在进行原型设计师时,会使用原型图软件,从产生想法到向开发人员提交项目。无论是构建基本线框还是功能齐全的原型,原型图软件都可以为你节省大量的时间和精力。 如果你是这个领域的新手或者想更新你的原型图软件包,请快速看…

iOS App的生命周期

App的生命周期 App从启动到退出的过程中,iOS应用程序不断从系统接收各种事件,如:用户点击了屏幕、用户点击了Home键,并对这些事件进行响应。接受事件是UIApplication对象的工作,但是,响应事件就需要由程序…

Dubbo详解

一、基础知识 1、 RPC RPC【Remote Procedure Call】是指远程过程调用,是一种进程间通信方式,他是一种技术的思想,而不是规范。它允许程序调用另一个地址空间(通常是共享网络的另一台机器上)的过程或函数, 而不用程序员显式编码…

【unity细节】—(Can‘t add script)脚本文件无法拖拽到对象的问题

👨‍💻个人主页:元宇宙-秩沅 hallo 欢迎 点赞👍 收藏⭐ 留言📝 加关注✅! 本文由 秩沅 原创 收录于专栏:unity细节和bug ⭐关于脚本文件无法拖拽到对象的问题⭐ 文章目录 ⭐关于脚本文件无法拖拽到对象的…

分治算法(Divide and Conquer)

本文已收录于专栏 《算法合集》 一、简单释义 1、分治算法 字面上的解释是“分而治之”,就是把一个复杂的问题拆分成两个或更多的相同或相似的子问题,再把子问题分成更小的子问题……直到最后子问题可以简单的直接求解,原问题的解即子问题的…

什么是FAQ页面?如何设计一个优秀的FAQ页面?

随着互联网技术的迅猛发展,越来越多的企业开始将在线客户支持服务作为一种重要的业务方式,以提供更好的服务体验。然而,在线客户支持服务除了提供实时的沟通方式外,一个功能齐全、易于使用的FAQ页面也是必不可少的,这可…

Go 语言进阶与依赖管理

作者:非妃是公主 专栏:《Golang》 博客主页:https://blog.csdn.net/myf_666 个性签:顺境不惰,逆境不馁,以心制境,万事可成。——曾国藩 文章目录 一、语言进阶1. 并发和并行2. 协程(Goroutine…

软件or硬件?硬件的前途到底在哪里?

一、硬件明明比软件更难,国内的硬件技术也不如软件,为什么硬件工程师待遇还不如软件? 1、不需要太高层次的硬件设计,比如大部分小家电企业,简单的电子产品企业,单片机简单外围设计就够了,单片机…

java网络编程——NIO架构

目录 1.什么是NIO 2.NIO结构 3.基于NIO下的聊天系统实现 4.Netty 1.什么是NIO NIO:java non-blocking IO,同步非阻塞IO。 BIO是阻塞IO,即每一个事件都需要分配一个进程给他,如果客户端没有连接上,则一直阻塞等待…

Java基础--->并发部分(1)

文章目录 线程基本概念线程的创建方式线程调度-------常用的方法线程的生命周期和状态并发编程的根本原因Java内存模型(JMM)多线程核心的根本问题volatile关键字保障原子性synchronized和ReentrantLock的区别 线程基本概念 ​ 进程是程序的一次执行过程,是系统运行程…

【Linux】1.4 基本权限

文章目录 一、shell 命令以及运行原理二、Linux 权限的概念三、Linux 权限管理01.文件类型和访问权限(事物属性)02.文件访问的分类(人)①用户分类②角色划分 03.文件权限值的表现方法04.文件访问权限的相关设置方法(a.…

STC8H8K64U单片机-看门狗配置与讲解

1、看门狗寄存器讲解 (bit7)WDT_FLAG:看门狗溢出标志,看门狗发生溢出时,硬件自动将此位置1,需要软件清零 (bit5)EN_WDT:看门狗使能位 0&#x…

被优化了怎么办?他苦学仨月拿到11koffer

网上有个段子叫做“生活就是起起落落落落落落”。人生在世,本就不易,再加上最近大环境影响,各行各业都在内卷,身为芸芸众生的一员,我们也难免受到影响,面临福利裁剪、降薪、甚至被优化的风险。 大环境我们…

面了20家大厂,发现这样介绍项目经验,显得项目很牛...

我在刚刚开始面试的时候,也遇到了这个问题,也是我第一个思考的问题,如何介绍自己的项目,既可以比较全面的让面试官了解这个项目,同时,也不会让面试官觉得废话太多。经过这么多的面试,我发现&…

JavaWeb+JSP+路径问题+跳转(HTML|Servlet|JSP)|这一篇就够了(超详细)

🙈作者简介:练习时长两年半的Java up主 🙉个人主页:老茶icon 🙊 ps:点赞👍是免费的,却可以让写博客的作者开兴好久好久😎 📚系列专栏:Java全栈,计…

ChatGPT真能取代程序员吗,看看它怎么解释SQL注入漏洞的问题

本文首发自「慕课网」,想了解更多IT干货内容,程序员圈内热闻,欢迎关注"慕课网"! 作者:Beerus|慕课网讲师 背景 本周在《Web安全渗透测试》课程的QQ群中,有同学提问了一个关于网上一个关于SQL注入…

大淘宝技术斩获NTIRE 2023视频质量评价比赛冠军(内含夺冠方案)

近日,CVPR NTIRE 2023 Quality Assessment of Video Enhancement Challenge比赛结果公布,来自大淘宝音视频技术团队的同学组成「TB-VQA」队伍,从37支队伍中脱颖而出,拿下该比赛(唯一赛道)冠军。此次夺冠是团…

Mysql replace into与on duplicate key update区别

1、replace into REPLACE INTO 首先判断数据是否存在;如果不存在,则插入;如果已存在则更新(先删除再插入 根据主键或唯一索引判断记录是否已存在,所以插入数据的表必须要有主键或者唯一索引!否则的话&…

Java 实现访问Redis哨兵(六)

目录 一、哨兵和复制 1.1 哨兵(sentinal) 1.Redis哨兵主要功能 2.Redis哨兵的高可用 1.2 Redis复制(Replication) 1.数据复制原理(执行步骤) 1.3 Redis 主从复制、哨兵和集群这三个有什么区别 二、Java访问哨兵实现 一、哨兵和复制 谈到Redis服务器的高可用&#xff0c…

【笔记】I2S协议是什么?

什么是I2S协议 I2S协议的介绍I2S协议有什么 这两天在搞ESP32的btAudio库,接触到了I2S,简单做个笔记。 I2S协议的介绍 I2S(Inter—IC Sound)总线, 又称集成电路内置音频总线,是飞利浦公司为数字音频设备之间的音频数据传输而制定的一种总线标…