Flat風(fēng)格的Qml輪選框

基于Qml的SpinBox控件修改而成。

demo.gif

輪選框代碼

import QtQuick 2.0
import QtQuick.Controls 2.0
import QtGraphicalEffects 1.0

SpinBox {
    id: root

    property color color: "#3498DB"

    value: 50
    editable: true

    contentItem: TextInput {
        text: root.value

        font.pixelSize: 15
        font.family: "Arial"
        font.weight: Font.Thin

        horizontalAlignment: Qt.AlignHCenter
        verticalAlignment: Qt.AlignVCenter

        readOnly: !root.editable
        validator: root.validator
    }

    up.indicator: Rectangle {
        x: root.mirrored ? 0 : parent.width - width
        implicitWidth: 37
        implicitHeight: implicitWidth
        color: root.up.pressed ? "#EBEDEF" : root.color

        Text {
            text: "+"
            anchors.fill: parent
            color: root.up.pressed ? root.color : "white"

            font.bold: true
            font.pixelSize: root.font.pixelSize * 2
            fontSizeMode: Text.Fit

            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
        }
    }

    down.indicator: Rectangle {
        x: root.mirrored ? parent.width - width : 0
        implicitWidth: root.up.indicator.implicitWidth
        implicitHeight: implicitWidth
        color: root.down.pressed ? "#EBEDEF" : root.color

        Text {
            text: "-"
            anchors.fill: parent
            color: root.down.pressed ? root.color : "white"

            font.bold: true
            font.pixelSize: root.font.pixelSize * 2
            fontSizeMode: Text.Fit

            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
        }
    }

    background: Rectangle {
        implicitWidth: 138
        border.color: "#EBEDEF"

        layer.enabled: root.hovered
        layer.effect: DropShadow {
            id: dropShadow
            transparentBorder: true
            color: "#EEF2F7"
            samples: 8 
        }
    }
}

輪選框樣式代碼

main_page2.png
GridLayout {
    width: root.width
    rows: 3
    columns: 3

    Repeater {
        model: ["#727CF5", "#0ACF97", "#F9375E",
                "#FFBC00", "#2B99B9", "#5A6268",
                "#EEF2F7", "#212730", "#3498DB"]

        SpinBox {
            value: Math.random() * 10
            color: modelData
        }
    }
}
  • 更多精彩內(nèi)容請(qǐng)關(guān)注公眾號(hào)Qt君。
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 如果有人問我,你最喜歡的明星是誰啊?我一定會(huì)毫不猶豫的驕傲的告訴他:楊冪,她是我的偶像,是我最最喜歡的姑娘啊。 今...
    橙子NY閱讀 447評(píng)論 1 1
  • 記得有一次,我打鼓剛剛回來,姐姐便羨慕地對(duì)我說:“成成,我也想去打鼓,你下次去問問老師我可不可以學(xué)呢?要不,...
    陽光成子閱讀 148評(píng)論 0 2
  • 周五晚上下班,去超市買上一箱科羅娜啤酒,再稱上兩個(gè)檸檬。她擰著兩個(gè)檸檬在前面,我抱著啤酒在后邊,一同往地下車庫(kù)走著...
    陽光小渣T閱讀 151評(píng)論 0 0

友情鏈接更多精彩內(nèi)容