日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Qt QML页面翻转控件封装

發布時間:2025/1/21 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Qt QML页面翻转控件封装 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言

用QML實現頁面翻轉,QML自帶控件Flipable已實現該功能,但是無法滿足我要的功能需求,于是在Flipable基礎上封裝了一下,添加翻轉過程中的動畫,在翻轉過程中修改頁面opacity、scale、angle。
最終效果圖如下:

代碼實現

先看封裝好的Flipable,命名為TLFlipable.qml

import QtQuick 2.6Flipable {id: containerproperty bool flipped: trueproperty int xAxis: 0property int yAxis: 1property int angle: 180width: front.widthheight: front.heightstate: "back"function flipableClick(){container.flipped = !container.flipped}transform: Rotation {id: rotation;origin.x: container.width / 2;origin.y: container.height / 2axis.x: container.xAxis;axis.y: container.yAxis;axis.z: 0}states: [State {name: "back";when: container.flippedPropertyChanges {target: rotation;angle: container.angle}}]transitions: Transition {SequentialAnimation {ParallelAnimation{NumberAnimation {target: container;property: "scale";to: 0.88;duration: 100}NumberAnimation {target: container;property: "opacity";to:0.7duration: 100;easing.type: Easing.Linear}}ParallelAnimation {NumberAnimation {target: container;property: "scale";to: 0.75;duration: 130}NumberAnimation {target: rotation;properties: "angle";duration: 290}NumberAnimation {target: container;property: "opacity";to:0.4duration: 290;easing.type: Easing.Linear}}ParallelAnimation{NumberAnimation {target: container;property: "scale"to: 1.0duration: 170}NumberAnimation {target: container;property: "opacity";to:1duration: 170;easing.type: Easing.Linear}}}} }

然后調用該控件FlipableTest.qml

import QtQuick 2.6Rectangle{width: 250height: 350TLFlipable{id:flipableanchors.fill: parentfront: rect1back: rect2MouseArea{anchors.fill: parentonClicked: {flipable.flipableClick()}}}Rectangle{id:rect1color:"red"width: parent.widthheight: parent.heightText {anchors.centerIn: parentfont.pixelSize: 30font.bold: truecolor:"white"text: qsTr("Page 1")}}Rectangle{id:rect2color:"green"width: parent.widthheight: parent.heightText {anchors.centerIn: parentfont.pixelSize: 30font.bold: truecolor:"white"text: qsTr("Page 2")}} }

最后用qmlscene執行FlipableTest.qml即可看到以上圖片的翻轉效果。

總結

以上是生活随笔為你收集整理的Qt QML页面翻转控件封装的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。