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

演示

视频讲解

相关推荐
jerry609几秒前
LLM笔记(六)线性代数
笔记·学习·线性代数·自然语言处理
ghost1435 分钟前
C#学习第23天:面向对象设计模式
开发语言·学习·设计模式·c#
Yan_ks31 分钟前
计算机组成原理——数据的表示
学习
freellf43 分钟前
go语言学习进阶
后端·学习·golang
真的想上岸啊1 小时前
学习51单片机02
嵌入式硬件·学习·51单片机
小刘要努力呀!1 小时前
嵌入式开发学习(第二阶段 C语言基础)
c语言·学习·算法
圈圈编码2 小时前
MVVM框架
android·学习·kotlin
凯雀安全2 小时前
printspoofer的RPC调用接口的简单代码
qt·网络协议·rpc
六bring个六4 小时前
文件系统交互实现
开发语言·c++·qt·交互
__BMGT()4 小时前
C++ QT图片查看器
前端·c++·qt