[Interest] Taking back a widget from a QBoxLayout?
René J.V. Bertin
rjvbertin at gmail.com
Fri Feb 22 17:27:27 CET 2019
Hi,
Consider
```
SomeWidgetClass *a = maybeReturnSomeWidget();
SomeOtherQWidgetClass *b = maybeReturnSomeOtherWidget();
QWidget *combined = new QWidget();
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(a);
layout->addWidget(b);
combined->setLayout(layout);
if (doWeLikeItCombined) {
return combined;
}
// get back our widgets
layout->removeWidget(a);
layout->removeWidget(b);
delete combined; // deleteLater()?
return a ? a : b;
```
The test on the combined widget looks at its size, which apparently I cannot get reliably from a->height(), b->width() and family directly.
I thus need to take back my widgets a and b from the layout and it seems that what I do currently isn't good enough because the code crashes when after I return something other than the combined widget.
Is this a catch-22 one can get out of?
Thanks,
R.
More information about the Interest
mailing list