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

演示

视频讲解

相关推荐
AOwhisky1 分钟前
Docker 学习笔记:网络篇
linux·运维·网络·笔记·学习·docker·容器
十年之少1 分钟前
使用VSCode 对PyQt5 say Hello—— Python + Qt 开发
vscode·python·qt
24白菜头3 分钟前
MySQL学习笔记
数据库·笔记·学习·mysql
小陈phd14 分钟前
多模态大模型学习笔记(三十九)——生成式与Transformer式OCR:从“像素抄录“到“文档智能“的完整演进
笔记·学习·transformer
泡泡以安22 分钟前
Unidbg学习笔记(一):为什么需要用户态模拟器
笔记·学习
栈溢出了40 分钟前
GNN 学习笔记:edge_index 与 W 参数矩阵
人工智能·笔记·神经网络·学习
yanyu-yaya1 小时前
css篇之网格grid 学习
前端·css·学习
YangYang9YangYan1 小时前
2026新媒体运营学习数据分析的价值
学习·数据分析·新媒体运营
Lucky_ldy1 小时前
C语言学习:字符函数和字符串函数(内容丰富且易懂)
c语言·开发语言·学习
czxyvX1 小时前
5-Qt系统相关
开发语言·qt