Qt/QML学习-Tumbler

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("Hello World")

    Tumbler {
        id: tumbler
        anchors.centerIn: parent
        // 只显示3个视图
        visibleItemCount: 3
        // 绘制背景视图
        background: Rectangle {
            border.width: 1
            radius: 10
        }

        // 模型
        model: ListModel {
            ListElement { value: "视图1" }
            ListElement { value: "视图2" }
            ListElement { value: "视图3" }
            ListElement { value: "视图4" }
            ListElement { value: "视图5" }
        }
        // 代理
        delegate: Rectangle {
            width: 100
            height: 50
            color: "transparent"
            Text {
                anchors.centerIn: parent
                text: value
                font.bold: true
                font.pointSize: 15
                color: tumbler.currentItem === this.parent? "red": "black"
                Rectangle {
                    y: parent.height + 5
                    color: "green"
                    width: parent.width
                    height: 2
                }
            }
            MouseArea {
                anchors.fill: parent
                hoverEnabled: true
                onEntered: {
                    color = "gray"
                    opacity: 0.5
                }
                onExited: {
                    color = "transparent"
                    opacity: 1
                }
            }
        }
        // 是否循环
        wrap: true
        // 视图加载完成时
        Component.onCompleted: {
            tumbler.currentIndex = 1
            tumbler.currentIndex = 0
        }
    }
}

演示

视频讲解

相关推荐
想进部的张同学1 小时前
hilinux-3599---设备学习---以及部署yolo
学习·yolo·海思
HyperAI超神经2 小时前
【vLLM 学习】Rlhf
人工智能·深度学习·学习·机器学习·vllm
做cv的小昊4 小时前
【TJU】信息检索与分析课程笔记和练习(7)数据库检索—Ei
数据库·笔记·学习·全文检索
AI360labs_atyun4 小时前
上海打出“开源”国际牌!2025重磅新政
人工智能·科技·学习·ai·开源
Chris_12194 小时前
Halcon学习笔记-Day6:工业视觉高级技术应用与实战项目
笔记·学习·halcon
GHL2842710905 小时前
调用通义千问(qwen-plus)模型demo-学习
学习·ai·ai编程
wdfk_prog6 小时前
[Linux]学习笔记系列 -- [fs]super
linux·笔记·学习
GHL2842710906 小时前
Temperature、Top P 学习
学习·ai
Yyuanyuxin7 小时前
保姆级学习开发安卓手机软件(三)--安装模拟机并开始简单的进入开发
android·学习
雒珣7 小时前
Qt简单任务的多线程操作(无需创建类)
开发语言·qt