ComboBox Selection

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

User avatar
POLSKASH
Not too shy to talk
Not too shy to talk
Posts: 44
Joined: Mon Jun 20, 2005 14:45

ComboBox Selection

Postby POLSKASH » Wed Jul 13, 2005 20:45

How do I set a "default" selection for a combobox? I tried
comboBox->setItemSelectState() but that had no effect.

User avatar
J_A_X
Quite a regular
Quite a regular
Posts: 72
Joined: Wed Jun 29, 2005 13:18
Contact:

Re: ComboBox Selection

Postby J_A_X » Wed Jul 13, 2005 20:50

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...)

User avatar
POLSKASH
Not too shy to talk
Not too shy to talk
Posts: 44
Joined: Mon Jun 20, 2005 14:45

Re: ComboBox Selection

Postby POLSKASH » Wed Jul 13, 2005 21:53

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.

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.

User avatar
J_A_X
Quite a regular
Quite a regular
Posts: 72
Joined: Wed Jun 29, 2005 13:18
Contact:

Re: ComboBox Selection

Postby J_A_X » Thu Jul 14, 2005 14:04

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:

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...

User avatar
POLSKASH
Not too shy to talk
Not too shy to talk
Posts: 44
Joined: Mon Jun 20, 2005 14:45

Re: ComboBox Selection

Postby POLSKASH » Thu Jul 14, 2005 16:45

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.

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Re: ComboBox Selection

Postby lindquist » Thu Jul 14, 2005 17:09

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]);
}

User avatar
arkos
Quite a regular
Quite a regular
Posts: 49
Joined: Thu Apr 27, 2006 21:45

Postby arkos » Thu Jun 01, 2006 04:43

that may set the text of the comboBox, but it doesn't select anything!

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

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Postby Rackle » Thu Jun 01, 2006 08:18

Here's what worked for me (adapted from Widget Galore):

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 7 guests