qml----Model/View入门(八)PathView

  pathview由model 、delegate、path三部分组成。Path的startX、startY用于描述路径的起点,而pathElements是个路径元素的列表,常见的路径元素有PathLine(直线) athQuad(赛贝尔二次曲线)、 PathCubic(赛贝尔三次曲线)、PathArc(椭圆上的一段弧)、PathCurve、PathSvg等。路径元素的终点就是整个路径的终点,终点可以和起点重合,如果重合那就表形成闭环。

  关于路径上点的坐标:除却PathSbvg之外,都有x、y属性。第一段路径的起点,就是startX,startY.终点以绝对坐标的形式表示,另外还可以通过relativeX、relativeY以相对起点坐标的形式定义终点坐标,同时也可以用绝对坐标和相对坐标的形式混合表示

  下面我们来看这几种常用的路径元素,元素路径不可见,但为了使路径可见,我用canvas画出来了。
  (1)PathLine  

Canvas{
        id: lineCanvas
        width: rootItem.width
        height: rootItem.height

        onPaint: {
            var ctx = getContext("2d")
            ctx.lineWidth = 2
            ctx.strokeStyle = "red"
            ctx.beginPath()
            ctx.moveTo(1, 1)
            ctx.lineTo(width-1, height-1)
            ctx.stroke()
        }

        Rectangle{
            id: lineBall
            width: 32
            height: 32
            radius: 16
            color: "blue"

            PathAnimation{
                id: lineAnim
                target: lineBall
                duration: 3000
                anchorPoint: "16,16"
                easing.type: Easing.Linear
                path: Path{
                    startX: 16
                    startY: 16
                    PathLine{
                        x: width-16
                        y: height-16
                    }
                }
            }

            MouseArea{
                anchors.fill: parent
                onClicked: lineAnim.start()
            }
        }
    }

  (2)PathQuad(贝塞尔曲线)。常见的贝塞尔曲线有二次方贝塞尔曲线、三次方曲线、四。。。贝塞尔曲线其实就是一条线,再加上几个控制点,然后再经过一个函数计算得来的。比如二次方贝塞尔曲线,由两个端点+一个控制点+一个函数生成;三次方贝塞尔曲线是由两个端点+两个控制点 +一个函数生成 贝塞尔曲线的起点是用startX.startY表示,用x,y表示终点,用controlX、controlY或者relativeControlX、relativeControlY来表示控制点
  下面我们来看一个二次方贝塞尔曲线  

Canvas{ //二次方贝塞尔曲线
        width: rootItem.width
        height: rootItem.height
        //visible: false

        onPaint: {
            var ctx = getContext("2d")
            ctx.lineWidth = 2
            ctx.strokeStyle = "red"
            ctx.beginPath()
            ctx.moveTo(0, 0)//下面的函数画出二次方的贝塞尔曲线
            ctx.quadraticCurveTo(0, height-1, width-1, height-1)
            ctx.stroke()
        }

        Text {
            anchors.centerIn: parent
            font.pixelSize: 20
            text: "quadratic Bezier curve"
        }
    }//二次方贝塞尔曲线 is end

  (3)PathCubic,它有两个控制点。直接上代码,在下面的代码中添加了动画处理  

Canvas{ //三次方贝塞尔曲线
        id: root
        width: rootItem.width
        height: rootItem.height
        //visible: false

        onPaint: {
            var ctx = getContext("2d")
            ctx.lineWidth = 2
            ctx.strokeStyle = "red"
            ctx.beginPath()
            ctx.moveTo(16,16)//下面的函数画出三次方的贝塞尔曲线
            ctx.bezierCurveTo(0, height-1 ,width-1, height/2, width-16, height-16);
            ctx.stroke()
        }

        Text{
            anchors.centerIn: parent
            font.pixelSize: 20
            text: "cubic Bezier curve"
        }

        Rectangle{
            id: ball
            width: 32
            height: 32
            radius: 16
            color: "blue"

            PathAnimation{
                id: pathAnim
                target: ball
                duration: 3000
                anchorPoint: "16, 16"
                easing.type: Easing.InCubic
                path: Path{
                    startX: 16
                    startY: 16
                    PathCubic{//这是三次方贝塞尔曲线
                        x: root.width -16
                        y: root.height-16
                        control1X: 0
                        control1Y: height-1
                        control2X: width-1
                        control2Y: height/2
                    }

//                    PathArc{//这是椭圆弧
//                        x: width /2
//                        y: height /2
//                        radiusX: 100
//                        radiusY: 100
//                        direction: PathArc.Clockwise
//                        useLargeArc: true
//                    }
                }
            }

            MouseArea{
                id: mouseArea
                anchors.fill: parent
                onClicked: pathAnim.start()
            }
        }
    }//三次方贝塞尔曲线 is end

  

 (4)PathArc它定义一段椭圆上的一段圆弧,其中起点和终点都一样,另外,椭圆上的两个半轴分别由radiusX、radiusY定义。direction控制圆弧的方向,默认值是PathArc,Clockwise(顺时针),另外还有一个比较使用的属性就是useLargeArc。因为即便是定义了各种属性条件,但是仍有两条弧满足条件-大、小圆弧。那么就可以通过useLargeArc来确定使用大弧还是小弧
  直接上弧的代码  

Path{
    startX: 100
    startY: 100
    PathArc{
        x: 100
        y: 100
        radiusX: 100
        radiusY: 100
        direction: PathArc.Clockwise
    }
}

  (5)PathCurve,定义一条Catmull-room曲线。上代码,用canvas画出来的
  

Canvas{
        width: rootItem.width
        height: rootItem.height
        contextType: "2d"
        visible: false

        Path{
            id: myPath
            startX: 4
            startY: 100

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

        onPaint: {
            context.strokeStyle = Qt.rgba(.4, .6 ,.8)
            context.path = myPath
            context.stroke()
            context.sttrokeStyle = "green"
            context.fillRect(2, 98, 4, 4)
            context.fillRect(73, 73, 4, 4)
            context.fillRect(198, 148, 4, 4)
            context.fillRect(323, 23, 4, 4)
            context.fillRect(392, 98, 4, 4)
        }
    }//room is end

  还有其它属性介绍--------------  

  PathPercent,放在组成路径的元素的后面,比如PathArc后面,指明它前面那部分路径所放置的Item数量占整个路径上所有Item数量的比率。需要注意的是在一个Path中使用PathPercent,PathPercent元素的value值是递增的,某一段路径如果在两个PathPercent之间,那么这段路径上面放置的Item数量占路径上总Item数量的比率,是它后面PathPercent与它前面PathPercent的value的差

  还有一个pathView,这个负责的有点多,好不知道怎么用,但下面的范例有点意思,留着以后用吧

  

import QtQuick 2.2

Rectangle {
    id: root
    width: 480
    height: 320
    color: "black"

    Component{
        id: rectDelegate

        Item{
            id: wrapper
            z: PathView.zOrder
            opacity: PathView.itemAlpha
            scale: PathView.itemScale
            Rectangle{
                width: 100
                height: 60
                color: Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
                border.width: 2
                border.color: wrapper.PathView.isCurrentItem ? "red" : "lightgray"
                Text{
                    anchors.centerIn: parent
                    font.pixelSize: 28
                    text: index
                    color: Qt.lighter(parent.color, 2)
                }
            }
        }
    }//rectDelegate is end

    PathView{
        id: pathView
        anchors.fill: parent
        interactive: true
        pathItemCount: 7
        preferredHighlightBegin: 0.5
        preferredHighlightEnd: 0.5
        highlightRangeMode: PathView.StrictlyEnforceRange

        delegate: rectDelegate
        model: 15
        focus: true
        Keys.onLeftPressed: decrementCurrentIndex()
        Keys.onRightPressed: incrementCurrentIndex()

        path:Path{
            startX: 10
            startY: 100
            PathAttribute{name: "zOrder"; value: 0;}
            PathAttribute{name: "itemAlpha"; value: 0.1;}
            PathAttribute{name: "itemScale"; value: 0.6}
            PathLine{
                x: root.width/2 - 40
                y: 100
            }

            PathAttribute{name: "zOrder"; value: 10;}
            PathAttribute{name: "itemAlpha"; value: 0.8;}
            PathAttribute{name: "itemScale"; value: 1.2}
            PathLine{
                x: root.width/2 - 60
                y: 0
            }

            PathAttribute{name: "zOrder"; value: 0;}
            PathAttribute{name: "itemAlpha"; value: 0.1;}
            PathAttribute{name: "itemScale"; value: 0.6}
        }

      MouseArea{
            anchors.fill: parent
            onWheel: {                
                if(wheel.angleDelta.y > 0)
                    pathView.decrementCurrentIndex()
                else
                    pathView.incrementCurrentIndex()
            }
        }
    }
}

 

转载于:https://www.cnblogs.com/SaveDictator/p/8244545.html

### 回答1: QML-QianWindow-V1版本界面是一款用户界面设计程序,它为开发人员提供了大量可自定义的UI组件,使得开发者可以轻松地创建美观、直观且易于使用的界面。QML-QianWindow-V1版本界面具有界面美观,易用性强以及可扩展性强的特点。该程序提供了多种UI组件如窗口、按钮、文本框、下拉框、进度条等等。每个组件都可以基于开发需求进行个性化设计,提高了程序的可读性和可维护性。 QML-QianWindow-V1版本界面的窗口设计功能令人称赞。用户可以定制窗口的样式、位置和大小等属性,使其符合自己的需求。同时,该程序支持类似IOS与Android风格的Tab、Panel、Dialog等视图控件,让应用的界面更具丰富性和交互性,提升用户体验。 此外,QML-QianWindow-V1版本界面可让用户通过实用的数据模型,快速地创建和管理表格和列表,包括多行、多列的表格和单选或多选列表,使得用户可以方便地处理大量数据。 总之,QML-QianWindow-V1版本界面通过提供易用性和可扩展性强的UI组件来简化界面设计过程,使得开发人员可以迅速开发出优秀的桌面应用程序界面,以满足用户高品质的界面需求。 ### 回答2: QML-Qianwindow-v1版本是一款基于QML语言开发的桌面应用程序,其主要特点是界面设计美观、简单易用,适用于多种应用场景。 该软件的主界面包含五个主要区域:侧边栏、消息中心、主视图、小部件和设置菜单。 侧边栏主要用于导航,其中包含主要的应用程序和功能,使用户可以轻松地进入不同的模块。 消息中心用于显示来自其他应用程序的通知,例如电子邮件或要完成的任务。 主视图是QML-Qianwindow-v1的核心区域,其中包含常见的功能和工具,例如打开的文件、书签和搜索栏。 小部件区域用于显示用户选择的小部件,例如天气预报和日历。 设置菜单区域包含应用程序的设置菜单,用户可以在此处更改应用程序的选项、主题和常规设置。 总体来说,QML-Qianwindow-v1版本的界面设计非常简洁,用户友好,易于使用。它增强了用户的生产力和效率,为用户提供了一种令人愉悦的使用体验。 ### 回答3: QML-QianWindow-v1是一种基于Qt QML开发的简单易用的窗口界面库。其设计风格简洁明了,适用于各种桌面应用开发。 该库主要由三个部分组成:Title Bar、Main Body和Sidebar。其中,Title Bar是窗口的标题栏,可以自定义标题、图标、按钮、菜单等。Main Body是页面的主体内容,可以显示各种控件、窗口和布局。Sidebar是侧边栏,可以显示常用的菜单、工具、快捷方式等。 在QML-QianWindow-v1中,可以使用QianWindow来创建窗口。QianWindow提供了常用的窗口操作方法,例如最小化、最大化、关闭等。同时,该库还提供了很多常用的QML组件,例如按钮、文本框、下拉框、列表框等,这些组件可以方便快捷地进行页面设计。此外,在QML-QianWindow-v1中还支持自定义样式,可以根据需要修改组件的颜色、形状、大小等。 QML-QianWindow-v1的界面设计风格简洁明了,同时具有一定的美观度。尤其是Title Bar部分的设计非常灵活,可以根据需要自由定制。Main Body部分支持多种布局方式,可以满足不同页面设计的需求。Sidebar部分则提供了丰富的快捷操作方式,提高了用户的使用效率。 总的来说,QML-QianWindow-v1是一款非常实用的界面库,可以方便快捷地进行桌面应用开发。无论是初学者还是有经验的开发者,都可以轻松使用该库进行界面设计。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值