[SOLVED] How to get an instance of a widget by its name?

Buckcherry

01-06-2008 16:26:12

How could I access to the properties of a widget only knowing its name?.

For example, I do this:

QuickGUI::Label mText = mSheet->createLabel("DebugText");
mText->setText((UTFString)"Test");
mText->setPosition(250,550);
mText->setSize(200,40);


Is there any way of change the text of mText using the mSheet?

Something like:

mSheet->getWidget("DebugText")->setText("New Text");

Any idea?

kungfoomasta

02-06-2008 18:48:59

If I remember correctly there is a "findWidget" function that is recursive.

Buckcherry

02-06-2008 20:02:45

The method findWidget returns a Widget* instance, but how can I convert from Widget* to QuickGUI::Label* for example?.

kungfoomasta

02-06-2008 20:29:22

dynamic_cast<Label*>(mSheet->getWidget("DebugText"))->setText("New Text");

dynamic_cast is used to convert a base class into a derived class. static_cast can also be used, but there are no checks and it is not as safe.

Buckcherry

02-06-2008 20:57:28

That's it.:-)

I didn't have the last update of the 0.9.7 version of QuickGUI, so I was unable to find the findWidget method.

Anyway, I got the result I wanted using:

dynamic_cast<QuickGUI::Label*>(mGUI->getSheet()->getChildWidget("DebugText"))->setText("Test");

Thanks! :-)