QML类型:PathCurve、PathAttribute、PathPercent

本文介绍了如何在QML中利用PathCurve和PathAttribute创建动态图形,通过PathView操纵项目间距,并展示了一个示例,演示了如何改变沿路径的项目属性如缩放和不透明度,实现视觉效果的变化。
摘要由CSDN通过智能技术生成

PathCurve

一、描述

PathCurve 提供了一种简单的方法来指定直接通过一组点的曲线。

import QtQuick 2.14
import QtQuick.Window 2.2

Window
{
    id:win
    visible: true
    width: 800
    height: 600

    Rectangle
    {
        id: window
        anchors.fill: parent

        Canvas
        {
            id: canvas
            anchors.fill: parent
            smooth: true

            onPaint:
            {
                var context = canvas.getContext("2d")
                context.clearRect(0, 0, width, height)
                context.strokeStyle = "blue"
                context.path = path
                context.stroke()
            }
        }

        Path
        {
            id:path
            startX: 0; startY: 100

            PathCurve { x: 75; y: 75 }
            PathCurve { x: 200; y: 150 }
            PathCurve { x: 325; y: 25 }
            PathCurve { x: 400; y: 100 }
        }
    }
}

二、属性成员

见:

QML类型:Path、PathLine、PathPolyline、PathMultiline、PathQuad、PathCubic

QML类型:PathArc、PathAngleArc​​​​​​


PathAttribute

一、描述

PathAttribute 对象允许为路径上的各个点指定由名称和值组成的属性。属性作为附加属性公开给委托。

下面的示例显示了一条路径,其中项目缩放到 30%,在路径顶部不透明度为 50%,在底部缩放为 100%,不透明度为 100%。 请注意使用 PathView.iconScale 和 PathView.iconOpacity 附加属性来设置委托的比例和不透明度。

import QtQuick 2.12
import QtQuick.Window 2.12
import Qt.labs.qmlmodels 1.0

Window
{
    width: 400;height: 400
    visible: true

    Rectangle
    {
        anchors.fill: parent

        Component
        {
            id: delegate
            Item
            {
                width: 80; height: 80
                scale: PathView.iconScale
                opacity: PathView.iconOpacity
                Column
                {
                    Image { anchors.horizontalCenter: nameText.horizontalCenter; width: 64; height: 64; source: icon }
                    Text { id: nameText; text: name; font.pointSize: 16 }
                }
            }
        }

        PathView
        {
            anchors.fill: parent
            model: ListModel
            {
                ListElement
                {
                    name: "张三"
                    icon: "qrc:/www.jpg"
                }
                ListElement
                {
                    name: "李四"
                    icon: "qrc:/www.jpg"
                }
                ListElement
                {
                    name: "王五"
                    icon: "qrc:/www.jpg"
                }
            }
            delegate: delegate
            path: Path
            {
                startX: 120; startY: 100
                PathAttribute { name: "iconScale"; value: 1.0 }
                PathAttribute { name: "iconOpacity"; value: 1.0 }
                PathQuad { x: 120; y: 25; controlX: 260; controlY: 75 }
                PathAttribute { name: "iconScale"; value: 0.3 }
                PathAttribute { name: "iconOpacity"; value: 0.5 }
                PathQuad { x: 120; y: 100; controlX: -20; controlY: 75 }
            }
        }
    }
}

二、属性成员

1、name : string

要更改的属性的名称。此属性将作为 PathView.<name> 提供给委托。

请注意,允许使用现有的 Item 属性名称(例如“opacity”)作为属性。这是因为路径属性添加了一个新的附加属性,它与现有属性没有任何冲突。

2、value : real

保存属性的值。指定的值可用于影响项目沿路径的视觉外观。


PathPercent

一、描述

PathPercent 可操纵 PathView 路径上项目之间的间距。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值