1.将需要添加的图片拷贝到工程中,最好是统一放在一个文件夹下。如:images/img.png
2.打开工程中qml.qrc文件夹
3.鼠标右键点击qml.qrc,在弹出的菜单中,选择"添加现有文件",进入到文件夹选择需要添加的图片文件即可。images文件夹也会自动加入到qml.qrc中。
4.在工程中加入的方法。
用Rectangle举例子:
Rectangle{
id:wndRectangle
width: parent.width
height: parent.height
color: "#0E3B73"
Image{
id:logo
x:sideWidth
y:footerHeight
width:120
height:50
fillMode:Image.PreserveAspectFit
source:"images/img.png"
}
}