Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 按qml按钮但无响应_Qt_Qml - Fatal编程技术网

Qt 按qml按钮但无响应

Qt 按qml按钮但无响应,qt,qml,Qt,Qml,我使用下面的代码设置了一个按钮 Button { x: 141 y: 312 width: 98 height: 22 text: qsTr("Hello World") anchors.verticalCenterOffset: 116 anchors.horizontalCenterOffset: -59 anchors.centerIn: parent MouseArea {

我使用下面的代码设置了一个按钮

Button {
    x: 141
    y: 312
    width: 98
    height: 22
    text: qsTr("Hello World")
    anchors.verticalCenterOffset: 116
    anchors.horizontalCenterOffset: -59
    anchors.centerIn: parent

    MouseArea
            {
                anchors.rightMargin: 126
                anchors.bottomMargin: -172
                anchors.leftMargin: -126
                anchors.topMargin: 172
                preventStealing: true
                anchors.fill: parent
                onPressed: {
                    console.debug("clicked!")

                }


            }
}
按下“hello world”按钮,它将在控制台上显示单击的内容

但当我点击按钮时,看起来什么都没发生


欢迎评论

首先,
QML
按钮
有自己的信号点击,因此您不需要
鼠标earea

其次,如果您想使用
MouseArea
,您也可以尝试单击
onClicked
信号并这样做:

Button {
    id: button1
    x: 8
    y: 19
    text: qsTr("Button")
    //        onClicked:  {
    //            console.debug("clicked!")
    //        }
    MouseArea{
        preventStealing: true
        anchors.fill: parent
        onPressed: {
            console.debug("clicked!")
        }
        onDoubleClicked:
        {
            console.debug("double clicked!")
        }
    }
}


QML按钮有自己的点击信号,所以你不需要鼠标earea,使用点击信号你是对的,谢谢,在这种情况下,我将此作为答案发布