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

演示

视频讲解

相关推荐
2601_952196363 分钟前
经济学专业学习数据分析的价值
学习·数据挖掘·数据分析
墨倾许14 分钟前
从零搭建运维学习环境(2026):WSL + Docker + Git + VS Code 完全指南
运维·git·学习·docker·容器·bash
渣渣灰958714 分钟前
VSCode开发环境开发Qt程序
ide·vscode·qt
读书札记202216 分钟前
Qt Creator 调试报错:Unable to create a debugging engine.
开发语言·qt
透明的玻璃杯17 分钟前
Qt Creator + Windows + Protobuf 最优方案(Mqqt通讯采用的方式)
开发语言·windows·qt
cpp_learners19 分钟前
QT 使用 QXlsx 时遇到包含 <private/qzipreader_p.h> 和 <private/qzipreader_p.h> 错误的解决方案
qt·qxlsx·quazip
月白风清江有声22 分钟前
下载电影开字幕(不是实时的ployer)
linux·学习
小新同学^O^38 分钟前
简单学习 --> 性能测试
学习
知识分享小能手39 分钟前
R语言入门学习教程,从入门到精通,R语言入门(3)
开发语言·学习·r语言
happymaker062643 分钟前
Spring学习日记——Day01(简单配置使用Spring,手写Spring的简单工厂模式)
java·学习·spring