Solved editable qcombobox entries
-
@user4592357
Then only insert those entries which pass your logic?? You choose which entries to insert, so we don't really know what you mean. -
@user4592357 I'm not sure I understand, but here's how I add entries to a combo box:
QList<QSerialPortInfo> list = QSerialPortInfo::availablePorts(); QList<QSerialPortInfo>::iterator p; // clear the list first. clear(); for (p = list.begin(); p != list.end(); ++p) { // your logic would go here: if (this entry passes my criteria, add it) addItem(p->portName()); }
-
@user4592357: I got it - editable combobox. you can add an input validator to the combobox'
lineEdit()
[1]. please see the help for details, I only have the phone at hand. -
@aha_1980
So he didn't mean "insert entries", he meant "validate text if user chooses to type something" ? -
@JNBarchan thats how i read the question :)
-
@aha_1980 as did I. So, do I understand your solution to mean that the OP would have to implement his own editor in order to add a validator?
-
@mzimmers
No, just add validator to existingQComboBox::lineEdit()
. -
@JNBarchan OK, I get it now...that's a pretty cool feature that I wasn't aware of. Qt is awesome...
-
ugh, so much had been going on while i wasn't here...
well, what i meant was, i have an editable combo box, and the user inputs something. i get the input and check if it's valid, then i add the string to the combo via addItem(). but it adds every string typed in. so maybe i need something to execute on else branch? like, delete this last added entry? but that's an ugly solution tbh
-
@user4592357 said in editable qcombobox entries:
i get the input and check if it's valid, then i add the string to the combo via addItem(). but it adds every string typed in.
Well if your code is wrong for the check validity call, or it passes as valid when it shouldn't, or you haven't actually attached the validator to the text correctly, that would behave as you describe! It's a bit hard to know if only you can see the code....
-
@JNBarchan it seems like you could prevent the edited string from being automatically added using the QComboBox::NoInsert option for enum QComboBox::InsertPolicy. I'm not sure, though, how you'd obtain the string the user created. If you could, you could of course validate and possibly insert it programmatically.
-
i had tried setInsertPolicy, but that won't even let me get press enter, i couldn't get the text cause the focus was just stuck on line edit. no everything is okay with validation, for wrong input i print something to the console, so the else branch of validation works, but the string still gets added.
-
@user4592357 Did you try what @aha_1980 suggested?
-
i don't need that, i just need to get all inputs, and choose which one i wanna add, there's no really a validator needed in my case. i'm accepting file paths, i only wanna add the file path to the combo if a file with such path exists