Qml按键事件传递

以示例说明Qml界面按键事件传递方式。

示例

  • 按下按键,由于first对象event.accepted = true隔断了事件的向上(父控件)传递;
  • 传递方式为由顶层(子控件)传向底层(父控件)。
Rectangle {
	id: second
    anchors.fill: parent
    Keys.onPressed: {
        console.log("Second Event")
    }

    Rectangle {
    	id: first
        anchors.fill: parent
        focus: true
        Keys.onPressed: {
            console.log("First Event")
            event.accepted = true
        }
    }
}

猜你喜欢

转载自blog.csdn.net/nicai_xiaoqinxi/article/details/89672110
今日推荐