How to create widgets at runtime?

Ripiz

07-04-2012 09:07:17

Hello,

I'm trying to figure how to create widgets at runtime, instead of loading from file, and place them inside specific widget (window), I tried few widget's methods but I couldn't get it work. Maybe anyone could help out?

// find window where to place widgets
MyGUI::Window *myWindow = GUI.findWidget<MyGUI::Window>("ToolWindow");

// create and initialize widget
MyGUI::TextBox *myLabel = myWindow->createWidget<MyGUI::TextBox>("", 30, 30, 100, 30, MyGUI::Align::Left | MyGUI::Align::Top);
myLabel->setCaption("MyLabel");

/* I thought this would be enough, but it wasn't. I tried the following lines individually, and their combination, but no luck */

myLabel->attachToWidget(myWindow);
myWindow->addChildItem(myLabel);

scrawl

14-04-2012 18:28:59

MyGUI::TextBox *myLabel = myWindow->createWidget<MyGUI::TextBox>("", 30, 30, 100, 30, MyGUI::Align::Left | MyGUI::Align::Top);

You are creating the widget with no skin (""). This means it will be invisible.

Otherwise, your code looks right (the last 2 lines are not needed)