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

演示

视频讲解

相关推荐
不羁的木木1 小时前
ArkWeb实战学习笔记04-JavaScript与Native通信
笔记·学习·harmonyos
程序员如山石1 小时前
QT标签左侧水平显示
qt
li星野1 小时前
RAG优化系列:HyDE(假设文档嵌入)——让LLM先写答案再检索
python·学习
知识分享小能手1 小时前
Flask入门学习教程,从入门到精通,Flask智能租房——用户中心知识点详解(9)
python·学习·flask
魔法阵维护师1 小时前
从零开发游戏需要学习的c#模块,第三十一章(技能冷却系统 —— 范围爆炸)
学习·游戏·c#
试剂界的爱马仕2 小时前
《古董局·终局5:潮生》第 4 章:藤田的棋局
人工智能·学习
searchforAI2 小时前
我的Obsidian知识库,现在可以自动剪藏笔记到本地了
人工智能·笔记·学习·音视频·ai工具·obsidian·视频总结
xcyxiner2 小时前
ubuntu下 cmake初始化脚本 以及 qt依赖
c++·qt
周末也要写八哥2 小时前
Visual C++6.0下载安装流程及PDF学习手册资源
c++·学习·pdf
坤坤藤椒牛肉面2 小时前
C++学习--类和对象
学习