前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >Flat风格的Qml单选/复选按钮

Flat风格的Qml单选/复选按钮

作者头像
Qt君
发布2019-11-24 16:11:04
发布2019-11-24 16:11:04
2.4K00
代码可运行
举报
文章被收录于专栏:跟Qt君学编程跟Qt君学编程
运行总次数:0
代码可运行

使用Qml的RadioButton与CheckBox控件修改而成。

单选按钮

  • RadioButton代码
代码语言:javascript
代码运行次数:0
运行
复制
import QtQuick 2.0
import QtQuick.Controls 2.0

RadioButton {
    id: root

    property color checkedColor: "#0ACF97"
    text: qsTr("RadioButton")

    indicator: Rectangle {
        x: root.leftPadding
        anchors.verticalCenter: parent.verticalCenter
        width: 26; height: width
        antialiasing: true
        radius: width/2
        border.width: 2
        border.color: root.checkedColor

        Rectangle {
            anchors.centerIn: parent
            width: parent.width*0.7; height: width
            antialiasing: true
            radius: width/2
            color: root.checkedColor
            visible: root.checked
        }
    }
}
  • RadioButton样式代码
代码语言:javascript
代码运行次数:0
运行
复制
GridLayout {
    width: root.width
    rows: 5

    Repeater {
        model: ["#727CF5", "#0ACF97", "#F9375E", "#FFBC00", "#2B99B9"]

        Column {
            spacing: 15

            RadioButton {
                text: "Radio Button 1"
                checked: true
                checkedColor: modelData
            }

            RadioButton {
                text: "Radio Button 2"
                checkedColor: modelData
            }

            RadioButton {
                text: "Radio Button 3"
                checkedColor: modelData
            }
        }
    }
}

复选按钮

  • CheckBox代码
代码语言:javascript
代码运行次数:0
运行
复制
import QtQuick 2.0
import QtQuick.Controls 2.0

CheckBox {
    id: root

    property color checkedColor: "#0ACF97"

    text: qsTr("CheckBox")

    indicator: Rectangle {
        x: root.leftPadding
        anchors.verticalCenter: parent.verticalCenter
        width: 26; height: width
        antialiasing: true
        radius: 5
        border.width: 2
        border.color: root.checkedColor

        Rectangle {
            anchors.centerIn: parent
            width: parent.width*0.7; height: width
            antialiasing: true
            radius: parent.radius * 0.7
            color: root.checkedColor
            visible: root.checked
        }
    }
}
  • CheckBox样式源码
代码语言:javascript
代码运行次数:0
运行
复制
GridLayout {
    width: root.width
    rows: 5

    Repeater {
        model: ["#727CF5", "#0ACF97", "#F9375E", "#FFBC00", "#2B99B9"]

        Column {
            spacing: 15

            CheckBox {
                text: "Check Button 1"
                checked: true
                checkedColor: modelData
            }

            CheckBox {
                text: "Check Button 2"
                checkedColor: modelData
            }

            CheckBox {
                text: "Check Button 3"
                checkedColor: modelData
            }
        }
    }
}
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-11-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Qt君 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 单选按钮
  • 复选按钮
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档