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,使用点击信号你是对的,谢谢,在这种情况下,我将此作为答案发布