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

演示

视频讲解

相关推荐
lpruoyu9 分钟前
【TODO】2026学习目标
学习
wjykp3 小时前
part5 dl的学习技巧
学习
hssfscv3 小时前
JavaWeb学习笔记——后端实战1_准备工作
笔记·后端·学习
hellodaoyan3 小时前
网络技术学习交换机原理作用让多台电脑通信
学习
运维管理4 小时前
h3c DHCP-学习篇
学习
好奇龙猫4 小时前
【人工智能学习-AI-MIT公开课-第9.约束:视觉对象识别(視覚対象認識)】
学习
qq19257230274 小时前
QT的QML
开发语言·qt
程序猿零零漆5 小时前
Spring之旅 - 记录学习 Spring 框架的过程和经验(八)基于Spring的注解应用
java·学习·spring
游戏23人生5 小时前
QT linux下 虚拟键盘使用及注意事项
linux·qt·计算机外设
·present·5 小时前
射频网课学习第二章(阻抗匹配 ch2-5到ch2-9部分)
学习