【QML学习】Component与Loader

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls

Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")

Loader{
    id: loader
    sourceComponent: com
    //width: 50
    //height: 50

}

Component{
    id: com
    AnimatedImage{
        id: animg
        source: "/resouce/test.gif"//路径
        speed: 2
    }

}

Button{
    id: btn
    width: 50
    height: 50
    x: 200

    onClicked: {
        loader.item.width = 100
        loader.item.height = 100
    }
}

}

posted @ 2025-01-14 19:58  隔壁老张爱吃鱼  阅读(32)  评论(0)    收藏  举报