以下是我的Qml代码:
Button { id: newMenu anchors { top: topMenu.top topMargin: 15 left: topMenu.left leftMargin: 16 } text: "New" iconSource: "../images/New.png" MouseArea { id: mouseArea anchors.fill: parent hoverEnabled: true //this line will enable mouseArea.containsMouse onClicked: { newProjectFileDlg.visible = true } onEntered: { console.log(tt1); } } style: ButtonStyle { id: buttonStyle background: Rectangle { id: tt1 implicitWidth: 100 implicitHeight: 25 border.width: 0 radius: 4 color: mousearea.entered ? "lightsteelblue" : "#2e2e2e" } }
我想访问此按钮的样式属性,当鼠标悬停时更改background.color.但是console.log outpu总是如此
qrc:/qmls/menu.qml:40: ReferenceError: tt1 is not defined
如何使用JavaScript获取元素?或者我们还有其他方法可以在输入鼠标时更改背景颜色.