View Full Version : [QT3] QComboBox: Disable adding items on Enter-keypress
BrainB0ne
13th January 2006, 11:28
Hello :)
I have a question.
Is it possible to disable the function of a editable QComboBox to add items on a Enter-keypress ?
see the screenshot, I don't want item1 to be added to the list when Enter is pressed.
http://img218.imageshack.us/img218/914/combobox5wp.jpg ( http://imageshack.us)
Thx in advance :D
wysota
13th January 2006, 12:04
Install an event filter on it and filter out the return and enter keys.
BrainB0ne
13th January 2006, 12:13
Install an event filter on it and filter out the return and enter keys.
So it means I have to subclass QComboBox (e.g MyComboBox) and override keyPressEvent by adding it to MyComboBox?
edit: thx wysota, you solved my problem :D
wysota
13th January 2006, 18:09
No, you have to apply an "eventFilter" (installEventFilter() and eventFilter()).
BrainB0ne
14th January 2006, 01:26
No, you have to apply an "eventFilter" (installEventFilter() and eventFilter()).
Thx! I will try it out on Monday at my work, didn't realize that you meant this..
The subclassing method worked also, but your solution looks better :D
wysota
14th January 2006, 02:22
Thx! I will try it out on Monday at my work, didn't realize that you meant this..
The subclassing method worked also, but your solution looks better :D
It's not "better". It's "quicker" and "simpler" :cool:
vitaly
14th January 2006, 16:26
May be you should try method setInsertionPolicy( QComboBox::NoInsertion).
BrainB0ne
14th January 2006, 20:43
May be you should try method setInsertionPolicy( QComboBox::NoInsertion).
Thank you also for your solution.. will try it out after this weekend :)
edit: Vitaly, I used your solution, seems to work great for my application :D
Powered by vBulletin® Version 4.2.5 Copyright © 2023 vBulletin Solutions Inc. All rights reserved.