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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Qt文档阅读笔记-QML RotationAnimation官方解析及实例

發布時間:2025/3/15 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Qt文档阅读笔记-QML RotationAnimation官方解析及实例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目錄

?

?

官方解析

博主例子


?

官方解析

RotationAnimation是一個屬性動畫,這個屬性控制圖片的旋轉。
默認情況下,他在給定的數值方向上旋轉,比如從0度順時針旋轉到240度,也可以逆時針旋轉比如從240度旋轉到0度。通過direction屬性來控制方向。
下面舉個例子

import QtQuick 2.0Item {width: 300; height: 300Rectangle {id: rectwidth: 150; height: 100; anchors.centerIn: parentcolor: "red"antialiasing: truestates: State {name: "rotated"PropertyChanges { target: rect; rotation: 180 }}transitions: Transition {RotationAnimation { duration: 1000; direction: RotationAnimation.Counterclockwise }}}MouseArea { anchors.fill: parent; onClicked: rect.state = "rotated" }}

注意:默認情況下旋轉是按照Item.Center。可以通過PropertyAction去設置其旋轉中心。

?

博主例子

下面的例子,有2個,第一個是把上面的官方例子,跑起來,第二個是做一個旋轉圖片的效果!

程序運行截圖如下:

程序結構如下:

源碼如下:

main.cpp

#include<QApplication> #include<QQuickView> #include<QColor> #include<QQmlContext> int main(int argc,char* argv[]) {QApplication app(argc,argv);QQuickView viwer;viwer.setSource(QUrl("qrc:/main.qml"));//viwer.setSource(QUrl("qrc:/test.qml"));viwer.show();return app.exec(); }

main.qml

import QtQuick 2.7 import QtQuick.Controls 1.2Rectangle{id:waitingRecvisible:trueanchors.fill: parentComponent.onCompleted: {animation.start()}Image{id:rotationanchors.centerIn: parentsource:"img/qq.png"RotationAnimation on rotation {id: animationduration: 1000loops: Animation.Infinitefrom: 0to: 360}} }

test.qml

import QtQuick 2.0Item {width: 300; height: 300Rectangle {id: rectwidth: 150; height: 100; anchors.centerIn: parentcolor: "red"antialiasing: truestates: State {name: "rotated"PropertyChanges { target: rect; rotation: 180 }}transitions: Transition {RotationAnimation { duration: 1000; direction: RotationAnimation.Counterclockwise }}}MouseArea { anchors.fill: parent; onClicked: rect.state = "rotated" } }

?

?

總結

以上是生活随笔為你收集整理的Qt文档阅读笔记-QML RotationAnimation官方解析及实例的全部內容,希望文章能夠幫你解決所遇到的問題。

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