How do I set a "default" selection for a combobox? I tried
comboBox->setItemSelectState() but that had no effect.
ComboBox Selection
Moderators: CEGUI MVP, CEGUI Team
Re: ComboBox Selection
First off, do you even look anywhere before you ask a question in here? A forum is made for questions/answers that aren't easy to find. I bet you can find the question to your answer just by searching the forums/api.
Second, you don't give out enough information. There could be a million and one reasons why your code doesn't work, but just stating one line of it won't help us do diddly squat. So please give out any and all info possible (actual code, log output, etc...)
Second, you don't give out enough information. There could be a million and one reasons why your code doesn't work, but just stating one line of it won't help us do diddly squat. So please give out any and all info possible (actual code, log output, etc...)
Re: ComboBox Selection
Of course I do, otherwise there would be about 15 times more posts in here by me. Now these are the only two functions that remotely describe what I want done here, and neither work. I tried mixing around the code like excluding the other stuff and just having the defaultItem. I also tried making the function call AFTER adding in my other stuff, still didn't work. So what do you suggest I do then?
If you need more info, here's some:
Note this uses setSelected() instead of setItemSelectState(), but neither of which work.
I add the defaultItem in first, and then my other crap.
If you need more info, here's some:
Note this uses setSelected() instead of setItemSelectState(), but neither of which work.
Code: Select all
defaultItem = new CEGUI::ListboxTextItem("Select user...");
defaultItem->setAutoDeleted(false);
defaultItem->setSelected(true);
comboBox->addItem(defaultItem);
//comboBox->setItemSelectState(defaultItem, true);
for(int i = 0; i < n; i++)
{
string tempStr = names[i].Name;
CEGUI::String temp(tempStr);
allNames[i] = new CEGUI::ListboxTextItem(temp);
comboBox->addItem(allNames[i]);
}
I add the defaultItem in first, and then my other crap.
Re: ComboBox Selection
Well, if I remember the tutorials and such, it said that everything you place on the screen is basically a window (ie. buttons, comboboxes, editboxes,etc). Which means that you have to create a window to actually create a combobox.
so you'd need something like the following:
Now, this isn't tested, but the TaharezLook/Combobox is clearly stated in the window factory and it's suppose to be basic knowledge that everything you place on the screen should be considered a window. Try adding the list to the new combobox.
Also, I'm suprised that it didn't give you an error...
so you'd need something like the following:
Code: Select all
CEGUI::Combobox* combobox = (CEGUI::Combobox*) CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/Combobox","combo1");
Now, this isn't tested, but the TaharezLook/Combobox is clearly stated in the window factory and it's suppose to be basic knowledge that everything you place on the screen should be considered a window. Try adding the list to the new combobox.
Also, I'm suprised that it didn't give you an error...
Re: ComboBox Selection
LOL man. That is code relevent to my problem. Of course I created a combobox window and whatnot. I'm not THAT lost with the GUI system. Everything is working fine for me, I just want one of the combobox items selected without the user even touching the combobox. Kinda like a default selection. That's all. If it's not possible, I guess I can live with it.
- lindquist
- CEGUI Team (Retired)
- Posts: 770
- Joined: Mon Jan 24, 2005 21:20
- Location: Copenhagen, Denmark
Re: ComboBox Selection
Just setting the text to that of the default should do it!
Code: Select all
defaultItem = new CEGUI::ListboxTextItem("Select user...");
defaultItem->setAutoDeleted(false);
comboBox->addItem(defaultItem);
comboBox->setText(defaultItem->getText());
for(int i = 0; i < n; i++)
{
CEGUI::String temp(names[i].Name);
allNames[i] = new CEGUI::ListboxTextItem(temp);
comboBox->addItem(allNames[i]);
}
that may set the text of the comboBox, but it doesn't select anything!
I tried the following:
and it seg faults on me. I believe it is because nothing is actually selected. So while setting the text is all well and good, I haven't found any real way of setting the selectedItem of the comboBox. Any ideas?
I guess the listboxTextItem is exactly that, a text item, but I would prefer to compare ID's rather than compare text strings everywhere in my code. I have searched the api reference and I don't think that there is a way to do what I am trying to do so instead I will just have to do:
to see what is selected
I tried the following:
Code: Select all
objectComboBox->getSelectedItem()->getID() == 1
and it seg faults on me. I believe it is because nothing is actually selected. So while setting the text is all well and good, I haven't found any real way of setting the selectedItem of the comboBox. Any ideas?
I guess the listboxTextItem is exactly that, a text item, but I would prefer to compare ID's rather than compare text strings everywhere in my code. I have searched the api reference and I don't think that there is a way to do what I am trying to do so instead I will just have to do:
Code: Select all
objectComboBox->getText()
to see what is selected
Here's what worked for me (adapted from Widget Galore):
Setting the combobox to read only prevents users from typing text within the Editbox and forces them to make a selection via the Listbox. This ensures that there will always be a selected item within the Listbox. You can then retrieve the ID via:
Code: Select all
Combobox* combobox = static_cast<Combobox*>(winMgr.getWindow("Combobox"));
combobox->setReadOnly(true);
ListboxTextItem* itemCombobox = new ListboxTextItem("Value 2", 2);
itemCombobox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
combobox->addItem(itemCombobox);
combobox->setText(itemCombobox->getText());
Setting the combobox to read only prevents users from typing text within the Editbox and forces them to make a selection via the Listbox. This ensures that there will always be a selected item within the Listbox. You can then retrieve the ID via:
Code: Select all
uint idCombobox = combobox->getSelectedItem()->getID();
Return to “Modifications / Integrations / Customisations”
Who is online
Users browsing this forum: No registered users and 1 guest