如何使用QML 5.2中的JavaScript访问一个按钮内的buttonStyle对象

  发布于 2023-02-05 11:17

以下是我的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获取元素?或者我们还有其他方法可以在输入鼠标时更改背景颜色.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有