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 小时前
Qt——QWidget
开发语言·qt
wdfk_prog2 小时前
[Linux]学习笔记系列 -- [drivers][i2c]i2c-dev
linux·笔记·学习
越努力越幸运5083 小时前
CSS3学习之网格布局grid
前端·学习·css3
chillxiaohan3 小时前
GO学习记录——多文件调用
开发语言·学习·golang
派葛穆4 小时前
Python-PyQt5 安装与配置教程
开发语言·python·qt
Funny_AI_LAB5 小时前
AI Agent最新重磅综述:迈向高效智能体,记忆、工具学习和规划综述
人工智能·学习·算法·语言模型·agi
初次见面我叫泰隆6 小时前
Qt——4、Qt窗口
开发语言·qt·客户端开发
代码游侠6 小时前
学习笔记——Linux内核与嵌入式开发1
linux·运维·前端·arm开发·单片机·嵌入式硬件·学习
宇钶宇夕6 小时前
CoDeSys入门实战一起学习(二十八):(LD)三台电机顺起逆停程序详解—上升、下降沿使用上
单片机·嵌入式硬件·学习
科技林总6 小时前
【系统分析师】6.5 电子商务
学习