QML控件大全之QmloverFlow

本文介绍了一个使用QML实现的CoverFlow效果,该效果可以滚动浏览一系列图片,并通过PathView组件来控制每个图片的旋转角度和缩放比例,以达到立体翻转的效果。代码中展示了如何设置PathView的路径属性来定制翻转动画。

QmloverFlow用于滚动浏览显示图片,效果如下

代码如下:CoverFlow.qml,FrmCoverFlow.qml,MyDelegate.qml

import QtQuick 2.0
import "./"
Rectangle {
    id: coverFlow
    color:"black"

    property ListModel model
    property int itemCount: 5

    PathView{
        id: pathView

        model: coverFlow.model
        delegate: MyDelegate{}

        path: coverFlowPath
        pathItemCount: coverFlow.itemCount
        anchors.fill: parent

        preferredHighlightBegin:0.5
        preferredHighlightEnd:0.5

    }

    Path{
        id: coverFlowPath
        startX: 0
        startY: coverFlow.height/3

        PathAttribute{ name:"iconZ"; value:0 }
        PathAttribute{ name:"iconAngle"; value:70 }
        PathAttribute{ name:"iconScale"; value: 0.6 }

        PathLine{ x:coverFlow.width*0.5; y:coverFlow.height/3; }
        PathAttribute{ name:"iconZ"; value:100 }
        PathAttribute{ name:"iconAngle"; value:0 }
        PathAttribute{ name:"iconScale"; value:1.0 }

        PathLine{ x: coverFlow.width; y:coverFlow.height/3 }
        PathAttribute{ name:"iconZ"; value: 0 }
        PathAttribute{ name:"iconAngle"; value:-70 }
        PathAttribute{ name:"iconScale"; value:0.6 }
        PathPercent{ value: 1.0 }
    }
}

import QtQuick 2.5
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4

Item {
    id: root
    visible: true
    width: 640
    height: 480
    ListModel{
        id: model
        ListElement{url:"./images/01.jpg"}
        ListElement{url:"./images/02.png"}
        ListElement{url:"./images/03.jpg"}
        ListElement{url:"./images/04.jpg"}
        ListElement{url:"./images/05.jpg"}
    }
    Rectangle{
        id: zhanwei
        anchors.left: parent.left
        width: root.width
        height: root.height/5
        visible:false
    }

    /*预计用来显示景区信息*/
    CoverFlow{
        id: coverFlow
        anchors.left: parent.left
        anchors.top: zhanwei.bottom
        anchors.topMargin: 10
        anchors.right: parent.right
        width: root.width
        height: root.height*2/5
        visible: true

        model:model
    }
}

import QtQuick 2.0

Item {
    id: delegateItem
    width: 320
    height: 450
    z: PathView.iconZ
    scale: PathView.iconScale

    Image{
        id: dlgImg
        source: url
        width:delegateItem.width
        height:delegateItem.height
    }
    transform:Rotation{
        origin.x: dlgImg.width/2.0
        origin.y: dlgImg.height/2.0
           axis{ x:0; y:1; z:0 }
        angle:delegateItem.PathView.iconAngle
    }
}

### QML 控件概述 QML 是一种声明式的语言,主要用于构建用户界面。它提供了丰富的控件集合,涵盖了从基本 UI 组件到复杂交互组件的各种需求。以下是常见的 QML 控件分类及其功能描述: #### 基本控件 - **Text 和 Label**: `Text` 用于显示简单的文本内容,而 `Label` 提供更强大的功能,例如支持 HTML 格式化文本[^2]。 - **Button**: 创建按钮并绑定点击事件处理逻辑。 - **Rectangle 和 Image**: 使用 `Rectangle` 定义矩形区域,常用来绘制背景或分隔线;`Image` 则用于加载和展示图像资源。 #### 列表与视图控件 - **ListView**: 实现滚动列表的功能,适合动态数据展示场景[^1]。通过模型 (`model`) 配合代理 (`delegate`) 来定义每一项的内容结构。 - **GridView**: 类似于 `ListView`,但它以网格形式排列项目。 - **PathView**: 支持沿着路径布局项目的高级视图控件。 #### 输入控件 - **TextField 和 TextInput**: 用户输入单行或多行文字的控件。 - **CheckBox 和 RadioButton**: 复选框和单选项控件,适用于多选或互斥选择场景。 - **Slider 和 Dial**: 调节数值范围的滑动条或旋钮控件。 #### 自定义绘图 - **Canvas**: 提供低级 API 进行动态图形渲染,例如实现水波纹效果或其他复杂的动画[^4]。 #### 图片列表视图 - **MyListViewPics (自定义)**: 可扩展的图片列表视图控件,允许开发者调整图片的高度和宽度等参数[^3]。 --- ### 示例代码:综合使用多种 QML 控件 以下是一个简单示例,展示了如何组合多个常见 QML 控件来创建一个完整的用户界面。 ```qml import QtQuick 2.15 import QtQuick.Controls 2.15 ApplicationWindow { visible: true width: 640 height: 480 title: "QML Controls Example" Column { spacing: 10 anchors.centerIn: parent // 文本标签 Label { text: "<b>Hello</b>, <i>World!</i>" font.pixelSize: 20 } // 按钮 Button { text: "Click Me" onClicked: console.log("Button clicked!") } // 单行输入框 TextField { placeholderText: "Enter your name..." } // 列表视图 ListView { model: ["Item 1", "Item 2", "Item 3"] delegate: Rectangle { width: parent.width height: 40 color: index % 2 === 0 ? "lightblue" : "white" Text { text: modelData anchors.centerIn: parent } } } } } ``` --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

vqt5_qt6

你的鼓励是我们创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值