gpt4 book ai didi

qt - TableView 上的 Keys.onPressed 调用了两次

转载 作者:行者123 更新时间:2023-12-03 18:03:15 24 4
gpt4 key购买 nike

我在使用 TableView 时发现了一些奇怪的行为.假设我们有以下代码:

TableView {
anchors.fill: parent
TableViewColumn { title: "column1"; role: "col1" }
TableViewColumn { title: "column2"; role: "col2" }
TableViewColumn { title: "column3"; role: "col3" }
model: ListModel {
ListElement { col1: "value1"; col2: "value2"; col3: "value3" }
ListElement { col1: "value4"; col2: "value5"; col3: "value6" }
ListElement { col1: "value7"; col2: "value8"; col3: "value9" }
}
Keys.onPressed: {
if(event.isAutoRepeat)
return;
if(event.key === Qt.Key_Space) {
console.log("Space pressed");
//event.accepted = true;
}
}
}

我得到的输出是:

qml: Space pressed

qml: Space pressed



这意味着 Keys.onPressed由于某种原因被调用了两次。如果我设置 event.acceptedtrue它按预期工作,但有时我只想检查按下的按钮而不接受它们。例如,如果按下向上箭头,我不想接受它。在这种情况下,处理程序被调用两次。

最佳答案

如果您将 Keys.onPressed 代码放在 TableView 范围之外,它可以正常工作,看起来像一个 Qt 错误...

关于qt - TableView 上的 Keys.onPressed 调用了两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35424570/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com