PDA

View Full Version : Capturing Key_up and Key_down for QTreeView



forrestfsu
21st February 2007, 16:45
I've attempted to capture key press events by both overriding keyPressEvent and event, but I am only able to capture the right arrow and left arrow keys. Any examples would help. I searched the forum...but all examples don't seem to work for me.

Thanks in advance.

jpn
21st February 2007, 18:26
Could we see some code? I don't have any problems catching Qt::Key_Up or Qt::Key_Down in keyPressEvent().

forrestfsu
23rd February 2007, 16:26
Unfortunately my dev machine crashed the other day...so I no longer have that code. However, looking at the situation I'm wondering if I'm over-complicating the problem.

I want to call a function whenever a new row is selected within a QTreeView. Right now I have this QTreeView connected using both the "entered" and "pressed" signal. This works fine as long as the user clicks and selects a new row. However, if the user uses the up and down arrow keys to change rows, my function does not get called. Rather then capturing the up and down arrow keys, is there an easier way to capture this event?

Thanks in advance.

jpn
23rd February 2007, 16:43
Yeah, you can use QAbstractItemView::selectionModel() to retrieve the item selection model and connect to one of it's signals, like QItemSelectionModel::selectionChanged().

forrestfsu
23rd February 2007, 17:44
Thanks JPN...I'll give that a shot!