PDA

View Full Version : How to change the QModelIndex with keyboard



aekilic
27th February 2010, 09:22
Dear All

For QTreeView I would like to change the model index by arrow keys. When I press down key I would like the model index to change like I click on the row.... Is there any signal for this?

Lykurg
27th February 2010, 10:01
You have to reimp QWidget/QTreeView::keyPressEvent() or install an event handler if you want that functionality even if your treeview does not have the focus.

aekilic
27th February 2010, 13:35
We have keyPressEvent but problem we have is,

when we move with arrow keys on the tree, model index does not change...

faldzip
27th February 2010, 13:41
AFAIK standard behavior is that you can change selection in views with arrow key by default. You can get signals from QItemSelectionModel which you can get with QTreeView::selectionModel()

aekilic
27th February 2010, 14:44
Dear My "Guru" friend...

I have all ready tried your smart idea, but it didn't work! Thank you for your smart idea! The selection you are talking about could be done with mouse, I am talking a selection with a mouse, user should navigate around the tree without mouse....

Lykurg
27th February 2010, 17:07
when we move with arrow keys on the tree, model index does not change... How does your code the move the selection look like? Normaly you cange with QAbstractItemView::setCurrentIndex() or directly via the selection model: selectionModel()->setCurrentIndex(/*...*/).

aekilic
1st March 2010, 22:02
Sorry for the late replies

The problem I had was from the qkeyevent,

Normaly on the widget when users hits to arrov key tree view comes to focus, and after that widget does not listen the key event... So there is no signal to get the selection. Do I need to re implement qtreeview?