tags:

views:

30

answers:

1

Hi,

I work on a Qt application in an embedded system and I only have a remote on which the main key is Key_space.

So, I would like to have a QComboBox on which you can select an item when pushing the Key_space button.

How to do it ? Maybe I should inherit from QComboBox and redefine keyPressEvent ?

+2  A: 

If Qt doesn't already handle this (and I would think it did, but could be mistaken), then you'll need to do a bit more than just handle the key press event in the combo box. When you are selecting an item for a combo box, another window has been shown with the list of items in it. You would need to handle the key press event for that window, somehow.

To do that, I would suggest inheriting from QComboBox, and install an event filter on the pop up that is shown (look at the showPopup(), hidePopup(), and view() functions). Make a slot that connects to the highlighted signal, and keep track of which index is highlighted. Then, when the popup window gets a space key event, hide the popup and set the current index to the last highlighted index.

Caleb Huitt - cjhuitt
Qt doesn't handle this with de Qt::Key_Space, but thanks to your answer it now works for me.
Tangui