JPro
26-06-2007 17:40:05
It seems to me that these two functions do not work as they should. They add/remove a child widget from the parent widget's mChildWidget's vector, but they fail to update the child widget's parent pointer.
For clarification, I needed to remove an image from one window and add it to another. If I simply did _removeChildWidget(image) and then _addChildWidget(image) to move it from the former parent to the new one, it would still move around as if it were a child of the former parent. A look into the source code of QuickGUIWidget showed that mParentWidget is never changed. This makes it so that when using setPosition(...) in relative mode, the widget moves to its original parent widget's positions, not it's current parent.
To fix this, I edited the following:
Let me know what you think. I have this overriding feeling that I've overlooked something.
For clarification, I needed to remove an image from one window and add it to another. If I simply did _removeChildWidget(image) and then _addChildWidget(image) to move it from the former parent to the new one, it would still move around as if it were a child of the former parent. A look into the source code of QuickGUIWidget showed that mParentWidget is never changed. This makes it so that when using setPosition(...) in relative mode, the widget moves to its original parent widget's positions, not it's current parent.
To fix this, I edited the following:
void Widget::_addChildWidget(Widget* w)
{
w->setParentWidget(this);
mChildWidgets.push_back(w);
}
void Widget::_removeChildWidget(Widget* w)
{
std::vector<Widget*>::iterator it;
for( it = mChildWidgets.begin(); it != mChildWidgets.end(); ++it )
{
if( (*it)->getInstanceName() == w->getInstanceName() )
{
mChildWidgets.erase(it);
w->setParentWidget(NULL);
break;
}
}
}
void Widget::setParentWidget(Widget* newParent)
{
if(mParentWidget != NULL)
{
getParentWidget()->_removeChildWidget(this);
}
mParentWidget = newParent;
}
Let me know what you think. I have this overriding feeling that I've overlooked something.