问题:invalid property name “style”?
问题描述:
在学习QML ButtonStyle时,遇到style一直标红,使用qmlscene
进行运行时,一直运行不过去,附上代码:
import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Controls.Styles 1.4
Rectangle
{
width: 320;
height: 240;
color: "gray";
Button
{
text: "退出";
anchors.centerIn: parent;
style: ButtonStyle
{
background: Rectangle
{
implicitWidth: 70;
implicitHeight: 25;
border.width: Control.pressed ? 2 : 1;
border.color: (Control.hovered || Control.pressed) ? "green" : "#888888";
}
}
onClicked:
{
Qt.quit();
}
}
}
问题截图:
问题解决:
这个问题是由于我导入最新的QtQuick.Controls 2.0
的模块,导致与QtQuick.Controls.Styles 1.4
版本有点不兼容,因此,我的解决方法是:使用QtQuick.Controls 1.x
版本,问题就解决了。