When working with TableViewI discovered strange behavior. Suppose we have the following code:
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");
}
}
}
and the output I get is:
qml: space click
qml: space click
This means that Keys.onPressedfor some reason it is called twice. If I installed event.acceptedin true, it works as expected, but sometimes I just want to check the buttons pressed without accepting them. For example, if you press the up arrow, I do not want to accept it. In this case, the handler is called twice.
source
share