setting a widget invisible through another

icaromotta

09-07-2010 22:08:28

Hi,

I can not understand why I can not access some functions when using findWidget through an event.

declaring:

QuickGUI::ListDesc * listaDesc = QuickGUI::DescManager::getSingleton().getDefaultListDesc();
listaDesc->resetToDefault();
listaDesc->widget_name = "List";
listaDesc->widget_dimensions = QuickGUI::Rect(100, 100, 480, 100);
QuickGUI::List *lista = mySheet->createList(listaDesc);
lista->createTextItem("Icaro", 0);


another widget than will set my list to invisible:

QuickGUI::Menu *m3 = m2->createSubMenu(segments);
m3->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_BUTTON_UP, &BaseApplication::setListVisible, this);


Here, the code

void BaseApplication::setListVisible(const QuickGUI::EventArgs& args)
{
const QuickGUI::WidgetEventArgs& wea = dynamic_cast<const QuickGUI::WidgetEventArgs&>(args);
QuickGUI::List *l = dynamic_cast<QuickGUI::List*>(wea.widget->findWidget("List"));

//crash here, because setVisible is protected
l->setVisible(! lista->getVisible());
}


The only solution to this would make the list a member of the class?

thanks.

kungfoomasta

10-07-2010 23:11:40

The reason setVisible is protected is so that widgets like MenuItems or ListItems can't be set invisible.

The code you wrote looks like it should work because you casted the Widget pointer to a List pointer, and the List class should have a public setVisible function. What is the compiler error that you get? I'm actually suspect of this line of code:

QuickGUI::List *l = dynamic_cast<QuickGUI::List*>(wea.widget->findWidget("List"));

I bet that l is NULL, because wea.widget is referring to the MenuItem, and there is no child widget "List" owned by the MenuItem.

icaromotta

12-07-2010 14:04:49

Yes, but so, how do I get the List ? It need to be a member class? Or, will have a method like getEntityByName of the Ogre?

Thanks

kungfoomasta

12-07-2010 18:09:44

You can store it as a member pointer, or if you want to look it up, you can find it from a widget that is most likely to find it:

QuickGUI::List *l = dynamic_cast<QuickGUI::List*>(mySheet->findWidget("List"));

The only reason this wouldn't work is if the List belongs to another sheet, or was removed from its Parent widget. (not in the hierarchy)