QML实现圆环颜色选择器

本文展示了如何利用QML实现一个圆环形状的颜色选择器,通过提供的项目源码和组件代码,读者可以了解到具体的实现细节,并可根据需求进行留言讨论。
摘要由CSDN通过智能技术生成

话不多说,先上效果图:
在这里插入图片描述
以上demo完整项目源码路径:
https://github.com/lesliefish/QMLInAction/tree/master/demos%26projects/Components/ColorSelector


ColorSelector组件代码如下,有问题可以留言:

import QtQuick 2.0
import QtQuick.Controls 2.2
Item {
    id:baseItem
    width: 350
    height: width
    signal colorChanged(string newColor);
    property int circleWidth: 40;//圆环宽度
    property var curColor: undefined;

    Rectangle {
        id: control
        width: baseItem.width
        height: width
        color: "transparent"
        border.width: 1
        border.color: "black"
        anchors.margins: 10

        // 根据角度获取颜色值
        function getAngleColor(angle) {
            var color, d;
            if (angle < Math.PI * 2 / 5) { // angle: 0-72
                d = 255 / (Math.PI * 2 / 5) * angle;
                color = '255,' + Math.round(d) + ',0'; // color: 255,0,0 - 255,255,0
            } else if (angle < Math.PI * 4 / 5) { // angle: 72-144
                d = 255 / (Math.PI * 2 / 5) * (angle - Math.PI * 2 / 5);
                color = (255 - Math.round(d)) + ',255,0'; // color: 255,255,0 - 0,255,0
            } else if (angle < Math.PI * 6 / 5) { // angle: 144-216
                d = 255 / (Math.PI * 2 / 5) * (angle - Math.PI * 4 / 5);
                color = '0,255,' + Math.round(d); // color: 0,255,0 - 0,255,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值