PDA

View Full Version : Detecting Enter in an editable QComboBox



wconstan
28th December 2009, 03:56
I have an editable QComboBox with an InsertAtCurrent insert policy. The trouble is that unless the user explicitly presses Enter, the new text the user has entered does not permanently change the text associated with the currentIndex. This makes sense actually but often times a user will enter the new text and simply left-click onto another widget, mistakenly assuming that the text they have just entered is set, only to find out later that it has not.

Q1: Is there an easy way that I can detect when a user has left-clicked off of the QComboBox widget so that I can programmatically set the text entered by the user (and emulate an Enter command)?

Q2: There is no editFinished signal available (by default) for the QComboBox widget. Can I create my own? If so, how?

Thanks!

spirit
28th December 2009, 06:24
take a look at QComoBobx::lineEdit, but there is important note


Only editable combo boxes have a line edit.

then if your combobox is editable you can simply catch lineedit's returnPressed or editingFinished signals.

wconstan
28th December 2009, 06:43
Worked like a charm Spirit! Thanks much for your help.