Qt文档阅读笔记-Image QML官方解析与实例
生活随笔
收集整理的這篇文章主要介紹了
Qt文档阅读笔记-Image QML官方解析与实例
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
目錄
?
?
官方解析
博主例子
?
官方解析
Image
Image用于展示圖片。
使用source屬性可以使用URL指定一張圖片。
只要是Qt能打開的圖片都支持,如果要展示動態(tài)圖,要使用:BnimatedSprite和AnimatedImage。
如果width和height屬性沒有被指定,將會使用圖像原來的大小。fillMode屬性可以使得圖像被拉伸和平鋪。
例子:
最簡單的圖像用法!
?
博主例子
此處的例子有2個功能,一個是補充官方的偽代碼,二是把以前的方圖,變化為圓圖(非拉伸)
程序運行截圖如下:
?
程序結(jié)構(gòu)圖如下:
源碼如下:
QMLImageDemo.pro
QT += core gui qml quickgreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsTARGET = QMLImageDemo TEMPLATE = appDEFINES += QT_DEPRECATED_WARNINGSSOURCES += main.cppHEADERS +=RESOURCES += \resources.qrcmain.cpp
#include <QApplication> #include <QQmlApplicationEngine> #include <QDebug>int main(int argc, char *argv[]) {QApplication a(argc, argv);QQmlApplicationEngine engine;engine.load(QUrl("qrc:/main.qml"));if(engine.rootObjects().isEmpty()){qDebug() << "engine load failed!";return -1;}return a.exec(); }main.qml
import QtQuick 2.7 import QtQuick.Controls 2.0 import QtGraphicalEffects 1.0ApplicationWindow {visible: truewidth: 300height: 300// Image {// anchors.centerIn: parent // source: "img/logo.png" // }Image {anchors.centerIn: parentid: pigpigpigsource: "img/logo.png"sourceSize: Qt.size(parent.width, parent.height)smooth: truevisible: false}Rectangle {id: maskwidth: parent.widthheight: parent.heightradius: height / 2color: "red"visible: false}OpacityMask {anchors.fill: pigpigpigsource: pigpigpigmaskSource: mask}}?
總結(jié)
以上是生活随笔為你收集整理的Qt文档阅读笔记-Image QML官方解析与实例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Flask笔记-构建mvc分层结构及优化
- 下一篇: Qt工作笔记-使用Qt中QProcess