QML中加载不同的图片的格式

1、加载本地图片——采用绝对路径的方式

//需要在绝对路径前加上:file:///  --->如果不加会出现QML Image: Protocol "h" is unknown盘符不认识的情况
image.source = "file:///H:/QT5/Qt Quick/images/add.png";
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2

Rectangle {
    width: 500;
    height: 300;

    //加载图片
    Image {
        id: image;
        asynchronous: true;//异步加载——在正在加载目标图片时显示加载图元
        cache: false;//不缓存
        anchors.centerIn: parent;
        fillMode: Image.PreserveAspectFit;//填充模式——等比拉伸

    }

    Component.onCompleted: {
        image.source = "file:///H:/QT5/Qt Quick/images/add.png";
   }
}

 

posted @ 2021-03-03 15:26  撑死算工伤吗  阅读(695)  评论(0编辑  收藏  举报