PDA

View Full Version : QComboBox Selection Validator?



chouqud
28th January 2014, 20:55
I have a QComboxBox presenting a list of choices and I'm connected to the currentIndexChanged signal.

My situation is that when the user makes a selection I respond to the signal by presenting an 'Are you sure?' messages box. If the user selects 'no' I would like to set the combobox back to the last selection - basically cancelling the currentIndexChanged action.

I've looked through the docs and I could only find a validator for the text being entered, not the choice itself. How can I do this?

anda_skoa
29th January 2014, 09:39
Not sure is this is what you are looking for, but the combo box has a QLineEdit child and it can have a QValidator set to validate its input.

Cheers,
_

chouqud
29th January 2014, 14:40
I'm not talking about validating the text that a user may enter. My combobox has the editable property set to false and the user selecting a new entry in the combox box via the dropdown menu.

For example, if I have a combobox with three entries [a,b,c] and the current selection is [a]. When the user selects [c], I would like to ask the user "Did you really mean to select [c]?" with a message dialog. If the user says "Yes" the we continue on - but if the user selects no then the selection of the combo box reverts back to the previously selected item.

I've attached a validator but it's validate function is not being called for this action.

anda_skoa
29th January 2014, 18:40
Ah, sorry, misread your original post.

The class that handles the signal and shows the message box will have to remember the last valid index and call setCurrentIndex() if the user rejects the change.

Cheers,
_