原創(chuàng)|使用教程|編輯:龔雪|2021-11-10 10:17:35.540|閱讀 350 次
概述:本文主要介紹QML中的可視化元素,歡迎下載框架產(chǎn)品體驗(yàn)~
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
對于最基本的可視化效果,Qt Quick提供了一個(gè) 類型來繪制矩形,這些矩形可以用顏色或垂直漸變著色,Rectangle 類型還可以在矩形上繪制邊框。
要繪制矩形以外的自定義形狀,請參閱類型或使用 類型顯示預(yù)渲染圖像。
import QtQuick Item { width: 320 height: 480 Rectangle { color: "#272822" width: 320 height: 480 } // This element displays a rectangle with a gradient and a border Rectangle { x: 160 y: 20 width: 100 height: 100 radius: 8 // This gives rounded corners to the Rectangle gradient: Gradient { // This sets a vertical gradient fill GradientStop { position: 0.0; color: "aqua" } GradientStop { position: 1.0; color: "teal" } } border { width: 3; color: "white" } // This sets a 3px wide black border to be drawn } // This rectangle is a plain color with no border Rectangle { x: 40 y: 20 width: 100 height: 100 color: "red" } }
Qt Quick提供了一個(gè)Image類型,可用于顯示圖像。 Image類型有一個(gè)source屬性,其值可以是遠(yuǎn)程或本地URL,或者嵌入在編譯資源文件中的圖像文件的URL。
// This element displays an image. Because the source is online, it may take some time to fetch Image { x: 40 y: 20 width: 61 height: 73 source: "http://codereview.qt-project.org/static/logo_qt.png" }
對于更復(fù)雜的圖像,還有其他類似于Image的類型。 BorderImage繪制帶有網(wǎng)格縮放的圖像,適用于用作邊框的圖像。 AnimatedImage播放動(dòng)畫 .gif 和 .mng 圖像。 AnimatedSprite和 SpriteSequence播放由以非動(dòng)畫圖像格式相鄰存儲的多個(gè)幀組成的動(dòng)畫。
Qt Quick提供的所有可視項(xiàng)都基于 Item 類型,它為可視項(xiàng)提供了一組通用的屬性,包括不透明度和變換屬性。
不透明度和可見性
Qt Quick提供的QML對象類型內(nèi)置了對不透明度的支持,可以對不透明度進(jìn)行動(dòng)畫處理,以允許平滑過渡到透明狀態(tài)或從透明狀態(tài)平滑過渡。 也可以使用可見屬性更有效地管理可見性,但代價(jià)是無法對其進(jìn)行動(dòng)畫處理。
import QtQuick Item { width: 320 height: 480 Rectangle { color: "#272822" width: 320 height: 480 } Item { x: 20 y: 270 width: 200 height: 200 MouseArea { anchors.fill: parent onClicked: topRect.visible = !topRect.visible } Rectangle { x: 20 y: 20 width: 100 height: 100 color: "red" } Rectangle { id: topRect opacity: 0.5 x: 100 y: 100 width: 100 height: 100 color: "blue" } } }
Qt Quick類型具有對轉(zhuǎn)換的內(nèi)置支持,如果您希望旋轉(zhuǎn)或縮放可視化內(nèi)容,您可以設(shè)置Item::rotation或Item::scale屬性,這些也可以是動(dòng)畫。
import QtQuick Item { width: 320 height: 480 Rectangle { color: "#272822" width: 320 height: 480 } Rectangle { rotation: 45 // This rotates the Rectangle by 45 degrees x: 20 y: 160 width: 100 height: 100 color: "blue" } Rectangle { scale: 0.8 // This scales the Rectangle down to 80% size x: 160 y: 160 width: 100 height: 100 color: "green" } }
Qt技術(shù)交流群4:166830288 歡迎一起進(jìn)群討論
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都網(wǎng)