Senzin
05-05-2013 01:24:36
So I have a window named "Window" and on it is a button. If I have a pointer to the button, how do I reliably get a pointer to the window it's on?
So I understand that widgets are composed of multiple widgets. But since one can take a button widget and attach it to a window widget, it seems reasonable that one could then ask that button what widget it's attached to. Calling getParent() three times works for a button on a window, but is that reliable for all widgets on all other widgets?
button->getParent()->getName(); // Returns "client"
button->getParent()->getParent()->getName(); // Returns empty
button->getParent()->getParent()->getParent()->getName(); // Returns "Window"
So I understand that widgets are composed of multiple widgets. But since one can take a button widget and attach it to a window widget, it seems reasonable that one could then ask that button what widget it's attached to. Calling getParent() three times works for a button on a window, but is that reliable for all widgets on all other widgets?