[QT3] QComboBox: Disable adding items on Enter-keypress (solved)
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
Thx in advance :D
Re: [QT3] QComboBox: Disable adding items on Enter-keypress
Install an event filter on it and filter out the return and enter keys.
Re: [QT3] QComboBox: Disable adding items on Enter-keypress (solved)
Quote:
Originally Posted by wysota
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
Re: [QT3] QComboBox: Disable adding items on Enter-keypress
No, you have to apply an "eventFilter" (installEventFilter() and eventFilter()).
Re: [QT3] QComboBox: Disable adding items on Enter-keypress
Quote:
Originally Posted by wysota
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
Re: [QT3] QComboBox: Disable adding items on Enter-keypress
Quote:
Originally Posted by BrainB0ne
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:
Re: [QT3] QComboBox: Disable adding items on Enter-keypress
May be you should try method setInsertionPolicy( QComboBox::NoInsertion).
Re: [QT3] QComboBox: Disable adding items on Enter-keypress
Quote:
Originally Posted by vitaly
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