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
        }
    }
}

演示

视频讲解

相关推荐
一隅论数智4 天前
给AI一张“业务概念地图“:本体如何从哲学走向企业智能
大数据·人工智能·经验分享·笔记·学习·学习方法·政务
XiHongShi20164 天前
STM32F407 RTC定时器例程,建议保存
stm32·单片机·学习
爱吃苹果的日记本4 天前
离散数学第六课
学习·离散数学
AI职业加油站4 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
旖旎夜光4 天前
力控面试题 01.01: 判定字符是否唯一(位运算) —— 题解
c++·学习·算法·leetcode·力控
奇思妙想聪明勤奋的小羊4 天前
DeepAgents第5章:子Agent 与上下文隔离—让 Agent学会委派
人工智能·python·学习·语言模型
霍霍的袁4 天前
【C++】map 和 set 的使用 | 从用法到底层
开发语言·c++·学习·visual studio
彧azz4 天前
Linux 环境下 Redis 学习总结:数据类型、持久化、锁、事务、主从与缓存问题
linux·redis·笔记·学习·面试
我爱cope4 天前
【操作系统 | 计算机硬件:CPU、内存与 I/O 如何支撑操作系统?】
学习·操作系统