View Full Version : QComboBox and item
drow
13th June 2006, 20:34
Hi,
I have a question:
I have 3 item in a combo: red, green, blue.
I want to remove "blue" but I don't have any index
Hou can I remove a item in QComboBox withuot use index?
bye!
Bojan
13th June 2006, 20:42
I don't know the specifics of your situation, but I guess you could clear the combobox, and then re-insert all the items except the "blue" one. But this isn't as nice as if you had the index.
Bojan
I have 3 item in a combo: red, green, blue.
Do you mean items named "red", "green" and "blue"?
Why don't you just search for it?
// iterate through the items and find the one to be removed
for (int = 0; i < combo->count(); ++i) {
if (combo->text(i) == "blue") {
combo->removeItem(i);
break;
}
}
// OR make use of QComboBox::setCurrentText()
combo->setCurrentText("blue");
combo->removeItem(combo->currentItem());
drow
14th June 2006, 08:25
I don't know the specifics of your situation, but I guess you could clear the combobox, and then re-insert all the items except the "blue" one. But this isn't as nice as if you had the index.
Bojan
I mast remove more item ( 100 - 800 item ) and this solution isn't efficent
// OR make use of QComboBox::setCurrentText()
combo->setCurrentText("blue");
combo->removeItem(combo->currentItem());
I'll try this solution
thk's all
drow
wysota
14th June 2006, 09:04
If you have this many items, it'll be best if you store indices of all items, for example in a QHash or something like that (but you have to use the model approach with persistant indices for that).
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.