Qt/QML学习-SpinBox

QML学习

main.qml

复制代码
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("SpinBox")

    SpinBox {
        id: spinBox
        anchors.centerIn: parent
        from: 0
        to: 100
        value: 50
        stepSize: 20
        editable: true
        background: Rectangle {
            implicitWidth: 200
            implicitHeight: 100
            border.width: 1
        }
        contentItem: Rectangle {
            TextInput {
                anchors.centerIn: parent
                text: spinBox.value
                font.pointSize: 30
                readOnly: !spinBox.editable
            }
        }
        down {
            indicator: Rectangle {
                implicitWidth: spinBox.background.width / 4
                implicitHeight: spinBox.background.height
                border.width: 1
                color: enabled?
                        spinBox.down.pressed? "gray": "white":
                        "lightGray"
                Text {
                    anchors.centerIn: parent
                    font.pointSize: 30
                    text: "-"
                }
            }
        }
        up {
            indicator: Rectangle {
                implicitWidth: spinBox.background.width / 4
                implicitHeight: spinBox.background.height
                x: spinBox.background.width - width
                border.width: 1
                color: enabled?
                        spinBox.up.pressed? "gray": "white":
                        "lightGray"
                Text {
                    anchors.centerIn: parent
                    font.pointSize: 30
                    text: "+"
                }
            }
        }
    }
}

演示

视频讲解

相关推荐
天选之子1231 小时前
DuckDB学习
jvm·学习
一只小菜鸡..2 小时前
Stanford CS144 学习笔记 (四):网络拥塞控制与 AIMD 算法
网络·笔记·学习
xuhaoyu_cpp_java2 小时前
SpringBoot学习(四)
java·经验分享·spring boot·笔记·学习
Eira-Z5 小时前
git(持续学习中...)
git·学习
子非鱼94275 小时前
07-Flutter 鸿蒙实战 07:故事集列表与缓存设计
学习·flutter·缓存·华为·harmonyos
fanchenxinok5 小时前
学习笔记:LabVIEW中如何将解析S19/HEX的VI封装为子VI并供主VI调用
笔记·学习·labview·子vi
2301_809051145 小时前
基本电子电路元件 学习笔记
笔记·学习
今天AI了吗6 小时前
Hermes Agent 搭建全流程:从本机试跑到可持续运行的个人 AI Agent
java·人工智能·python·学习·embedding
一只小菜鸡..7 小时前
Stanford CS144 学习笔记 (二):传输层与数据通信机制
网络·笔记·学习
天选之子1237 小时前
tabulate学习
学习