Okay, I've gotten it working by going like this:
void FlowLayout
::insertWidgetAt(QWidget *widget,
int index
) {
widget->setParent(this->parentWidget());
}
void FlowLayout::insertWidgetAt(QWidget *widget, int index)
{
widget->setParent(this->parentWidget());
this->itemList.insert(index, new QWidgetItem(widget));
}
To copy to clipboard, switch view to plain text mode
So all I needed to do was make sure the widget being added actually knows who its parent is.
I suppose 'QLayout::addWidget()' normally does it, before passing the widget as a item to 'myCustomLayout::addItem()', but since I couldn't find the source for QLayout, I can't be sure.
[Edit:] Found the QLayout source. Apparently the proper and safer call is 'QLayout::addChildWidget()':
void FlowLayout
::insertWidgetAt(QWidget *widget,
int index
) {
}
void FlowLayout::insertWidgetAt(QWidget *widget, int index)
{
QLayout::addChildWidget(widget);
this->itemList.insert(index, new QWidgetItem(widget));
}
To copy to clipboard, switch view to plain text mode
This is what QLayout::addWidget() calls internally, and it checks for a number of different circumstances making the code more robust.
Bookmarks