Re-parent a window/widget

simed

16-01-2012 16:40:40

What is the right way to change a Window's parent? I have a 'dialog' (a Window with child widgets) and initially it is a root widget. But I want to be able to toggle it from being a root widget, to being a parent of another Window.

I wasn't sure if addChildItem, etc, are the right way - I keep getting crashes.

Altren

16-01-2012 21:13:40

Try Widget::attachToWidget:
widget->attachToWidget(newParentWidget);

simed

16-01-2012 21:49:57

Thanks, I was sure I'd seen/used it before but my mind went blank after too much coding ;)

simed

17-01-2012 10:07:31

I'm seeing a discrepancy between loading a layout and then re-parenting, and loading a layout with a specified parent.

e.g:
Widget *dlg = LayoutManager::getInstance().loadLayout("test.layout").front();
dlg->AttachToWidget(parent,WidgetStyle::Overlapped);


Vs
LayoutManager::getInstance().loadLayout("test.layout","",parent).front();

My .layout looks like:
<?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Layout" version="3.2.0">
<Widget type="Window" skin="WindowCSX" position="0 0 150 280" layer="Overlapped" name="SceneInfoDlg">
Is there a simple fix, or should I just load and then re-parent?

Altren

17-01-2012 14:07:52

I don't understand your question, what's your problem and where is discrepancy?
Also loadLayout with parent is same as AttachToWidget with default WidgetStyle (i.e. Child), but not Overlapped.

simed

17-01-2012 15:51:45

When I use loadLayout with parent specified, you get the render overlapping issues. But your answer explains why - loadLayout doesn't let me specify child/overlapped/etc so I need to manually re-parent.

Altren

17-01-2012 15:55:19

Overlapped and other child styles can be specified in layout.

simed

17-01-2012 16:09:25

Overlapped and other child styles can be specified in layout.I included the top of my .layout - it specifies use of overlapped layer. But if I call loadLayout with the parent, it doesn't do overlapping properly. I can post more of the .layout if needed, do all widgets need the layer setting or just the top one?

Maybe I need to set style in the .layout too... but LayoutEditor doesn't seem to allow this. In my .layout I have a single Window with child widgets, as a kind of dialog template. I load and display this as a child of another widget. Maybe Overlapped layer is not most sensible in this scenario... Popup looks possible?

Altren

17-01-2012 19:56:12

I included the top of my .layout - it specifies use of overlapped layer.This is just layer name and it doesn't mean anything.

Maybe I need to set style in the .layout too...You need to set style as well, and yeah, you can't do that in LE now. (style="Overlapped")

simed

17-01-2012 20:31:13

That's great, thanks.