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: "+"
                }
            }
        }
    }
}

演示

视频讲解

相关推荐
娇娇yyyyyy35 分钟前
QT编程(15): Qt 按键事件和定时器事件
开发语言·qt
炽烈小老头1 小时前
【每天学习一点算法 2026/03/22】前 K 个高频元素
学习·算法
神舟之光1 小时前
Java面向对象编程知识补充学习-2026.3.21
java·开发语言·学习
网络工程小王2 小时前
【大数据技术详解】——Kibana(学习笔记)
大数据·笔记·学习
im_AMBER2 小时前
Leetcode 144 位1的个数 | 只出现一次的数字
学习·算法·leetcode
red_redemption2 小时前
自由学习记录(144)
学习
adore.9682 小时前
3.20 复试学习
学习
Master_oid3 小时前
机器学习35:元学习的应用
人工智能·学习·机器学习
想七想八不如114083 小时前
SQL操作学习
数据库·sql·学习
雷工笔记4 小时前
AI使用|通过AI学习物料分类编码表
笔记·学习