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 小时前
[LangGraph] 学习笔记(053):工作流模式(二)—— LLM 结构化路由
数据库·笔记·学习
路灯上の马陈1 小时前
Java File类2 练习 学习笔记
java·笔记·学习
li星野2 小时前
C++/Qt 开发避坑与重构原则清单 (速记版)
c++·qt·重构
沫璃染墨3 小时前
《Qt从零入门系列(十七):网络编程基础详解——从Socket原理到TCP/UDP通信API》
开发语言·网络·c++·qt·http·qt5·qt6.3
ShineWinsu3 小时前
对于Qt:绘图的解析
开发语言·数据库·c++·qt·面试·客户端·绘图
sharemylove4 小时前
Java 面向对象(OOP)笔记
java·开发语言·笔记·学习·课程设计
潇湘散客4 小时前
PlantAis插件更新:RVM负实体开关;VUE文件读取与导出等
c++·qt·opengl
DKPT4 小时前
AI编程助手新利器skills火爆登场
人工智能·笔记·学习·开源·ai编程
往谏不追4 小时前
零基础掌握Prompt Engineering工程
学习·prompt
yiangL_5 小时前
自主学习:Python 嵌套循环实验|双层循环与图形打印实践
开发语言·python·学习