1.使用Button时候,自定义background遇到错误:
qrc:/main.qml:28:29: QML QQuickImage: The current style does not support customization of this control (property: "background" item: QQuickImage(0x28465ce2350, parent=0x0, geometry=0,0 113x112)). Please customize a non-native style (such as Basic, Fusion, Material, etc). For more information, see: https://doc.qt.io/qt-6/qtquickcontrols2-customize.html#customization-reference
解决办法
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Controls.Basic 2.15 //主要是加这一句
Button {
id: carBtn
checkable:true;
background: Image {
width: 113
height: 112
source: carBtn.checked ? "qrc:/images/car_sel.png" : "qrc:/images/car_normal.png";
}
}
主要加上
import QtQuick.Controls.Basic 2.15就可以去掉警告并且hover样式也是对的