PDA

View Full Version : QcomboBox autoCompletion



Lele
11th July 2006, 14:18
Hi all,
hoping this won't be a trivial question, I'd like to know if it's possible to prevent the user from entering invalid data when filling a QComboBox editable with autoCompletion.
I mean, I have a list of Countries and to help the user I set the combo editable, but I don't want that user could write and leave invalid data (such as Germanysd...)
I can check after but I'd like to avoid any invalid data to appear.
thanks in advance

bye

jpn
11th July 2006, 14:30
Write a validator and set it with QComboBox::setValidator().

Lele
11th July 2006, 16:28
thanks for replying,
I can't figure it out how to write the QValidator::validate to accomplich my requirements,
maybe I could check when user lost focus from the combo and put the closest string from the possible items.
thanks again

jpn
11th July 2006, 16:44
Don't give up. It's not so complicated! :)

QComboBox uses a QStringListModel. Pass a QStringList fetched from the model to the validator to validate against. Here's a pseudo algo suggestion for QValidator::validate()


if stringlist contains input
return Acceptable
else if input is empty or any string in the stringlist starts with input
return Intermediate
else
return Invalid