Qt5 中QButton的背景图片为png格式的 ,QLabel的背景图片是jpg格式的注意区分,新人学习记住吧。
最近在学习qml中时不知button怎么设置背景图片,用的的是qt5.7.1,经过自己的摸索得出结果还算不错,能够自适应button的大小。源码如下:
Button {
id: button1
text: qsTr("Press Me")
Image {
id: button1Image
width: parent.width
height: parent.height
source: "qrc:/5.png"
}
}