0

Let's say I have a list of items like:

"01 Apple 1", 
"02 Apple 2", 
"03 Banana", 
"04 Orange 1", 
"05 Orange 2"

Is there a way to make a QComboBox where the user can (for example) press "o" to select "04 Orange 1" and "b" to select "03 Banana"?

rmweiss
  • 716
  • 1
  • 6
  • 16
  • I can't see any easy way to do this without losing some functionality. For instance do you want to retain the currently functionality where hitting the zero key will cycle through the options? If someone hits `o` twice, should it go to '04 orange 1' on the first press and then '05 Orange 2' on the second press? If someone hits 'or' do you want it to stay with orange, or ignore the initial 'o' and jump to an entry that starts '00 r..'? Are the 01, 02, etc numbers important? Can they be hidden or drawn separately? – three_pineapples Oct 17 '14 at 23:50
  • It should work just like an normal QComboBox, just with the difference that it ignores the first X (in this case 3) characters and uses the next one for everything it would use the first one normaly. – rmweiss Oct 23 '14 at 17:21

1 Answers1

0

You can use an event filter for this purpose. Install an event filter for your combo box. If the event type is QEvent::KeyPress, find out which key is pressed and if it is of your interest, emit a signal with the necessary information to your widget/dialog/mainwindow which houses the combo-box.

You can find an example here.

Nithish
  • 1,580
  • 12
  • 21