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

演示

视频讲解

相关推荐
词元Max14 小时前
Java 转 AI Agent 开发学习路线(2026年3月最新版)
java·人工智能·学习
星幻元宇VR15 小时前
VR互动平台|开启沉浸式体验新方式
科技·学习·安全·vr·虚拟现实
qqacj16 小时前
Spring Security 官网文档学习
java·学习·spring
南無忘码至尊16 小时前
Unity学习90天 - 第 6 天 -学习物理 Material + 重力与阻力并实现弹跳球和冰面滑动效果
学习·unity·游戏引擎
小陈phd16 小时前
多模态大模型学习笔记(三十六)—— 扩散模型与可控生成:从AI涂鸦到精准作画的技术革命
人工智能·笔记·学习
輕華17 小时前
PyQt5入门实战:安装、QtDesigner设计与PyUIC转换完整指南
开发语言·qt
Sss_Ass17 小时前
跟着老师不迷路系列---跟着李述铜老师学习汇编语言之基本汇编程序符号绑定语句
学习·嵌入式·汇编语言·李述铜·符号绑定语句
for_ever_love__17 小时前
UI 学习 Appearance 外观管理
学习·ui·ios·objective-c
雾岛听蓝17 小时前
Qt Widget控件属性详解
开发语言·经验分享·笔记·qt