QTableWidget: How to intercept up/down arrow keys
-
I have some cells in my table that are marked as non-selectable. This is impeding the up/down arrow keys.
E.g. in a 3x3 table perhaps cell 1,1 is non-selectable. But I want to have my code decide where to move the selection next
when the up/down keys are pressed.
How can I intercept these key-presses?
Thanks. -
I have some cells in my table that are marked as non-selectable. This is impeding the up/down arrow keys.
E.g. in a 3x3 table perhaps cell 1,1 is non-selectable. But I want to have my code decide where to move the selection next
when the up/down keys are pressed.
How can I intercept these key-presses?
Thanks.@Publicnamer Did you subclass QTabWidget and override https://doc.qt.io/qt-6/qwidget.html#keyPressEvent?
-
I think it might be easier to reimplement
moveCursor
(https://doc.qt.io/qt-6/qabstractitemview.html#moveCursor) -
I think it might be easier to reimplement
moveCursor
(https://doc.qt.io/qt-6/qabstractitemview.html#moveCursor)@VRonin I just tried moveCursor. I am finding that sometimes moveCursor is not being called in response to up/down arrows. Typically it is right after I have called setCurrentCell.
@jsulm I also just tried keyPressEvent and I find it's not being called in the same situation.
In each case, the arrow keys are ignored until I click somewhere in the table, even though I had just been interacting with the table.
-
@VRonin I just tried moveCursor. I am finding that sometimes moveCursor is not being called in response to up/down arrows. Typically it is right after I have called setCurrentCell.
@jsulm I also just tried keyPressEvent and I find it's not being called in the same situation.
In each case, the arrow keys are ignored until I click somewhere in the table, even though I had just been interacting with the table.
@Publicnamer said in QTableWidget: How to intercept up/down arrow keys:
even though I had just been interacting with the table.
Does the tablewidget have focus? you might be moving the focus on another widget in another operation
-
@Publicnamer said in QTableWidget: How to intercept up/down arrow keys:
even though I had just been interacting with the table.
Does the tablewidget have focus? you might be moving the focus on another widget in another operation
@VRonin Yes, that was it, thanks. Movecursor is working fine now.