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

Flat风格的Qml按钮

作者头像
Qt君
发布2019-11-15 15:37:16
9260
发布2019-11-15 15:37:16
举报
文章被收录于专栏:跟Qt君学编程

使用Qml的Button控件修改而成。

源码

  • Button源码
代码语言:javascript
复制
import QtQuick 2.0
import QtQuick.Controls 2.0
import QtGraphicalEffects 1.0

Button {
    id: root
    property color backgroundDefaultColor: "#4E5BF2"
    property color backgroundPressedColor: Qt.darker(backgroundDefaultColor, 1.2)
    property color contentItemTextColor: "white"

    text: "Button"
    contentItem: Text {
        text: root.text
        color: root.contentItemTextColor
        font.pixelSize: 15
        font.family: "Arial"
        font.weight: Font.Thin
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
        elide: Text.ElideRight
    }

    background: Rectangle {
        implicitWidth: 83
        implicitHeight: 37
        color: root.down ? root.backgroundPressedColor : root.backgroundDefaultColor
        radius: 3
        layer.enabled: true
        layer.effect: DropShadow {
            transparentBorder: true
            color: root.down ? root.backgroundPressedColor : root.backgroundDefaultColor
            samples: 20
        }
    }
}
  • 按钮组样式源码
代码语言:javascript
复制
GridLayout {
    anchors.centerIn: parent
    rows: 3
    columns: 3
    rowSpacing: 30
    columnSpacing: 30

    Button {
        text: "First"
        backgroundDefaultColor: "#727CF5"
    }

    Button {
        text: "Secondary"
        backgroundDefaultColor: "#5A6268"
    }

    Button {
        text: "Success"
        backgroundDefaultColor: "#0ACF97"
    }

    Button {
        text: "Danger"
        backgroundDefaultColor: "#F9375E"
    }

    Button {
        text: "Warning"
        contentItemTextColor: "#313A46"
        backgroundDefaultColor: "#FFBC00"
    }

    Button {
        text: "Info"
        backgroundDefaultColor: "#2B99B9"
    }

    Button {
        text: "Light"
        contentItemTextColor: "#313A46"
        backgroundDefaultColor: "#EEF2F7"
    }

    Button {
        backgroundDefaultColor: "#212730"
        backgroundPressedColor: "#313A46"
    }

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

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

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

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

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