quick question. Is there any way to (easily) retrieve the parent layout of a widget in Qt?
PS: QObject::parent() won't work, for logical reasons.
EDIT: I'm positive the widget has a parent layout, because I added it to a layout earlier in the code. Now, I have many other layouts in the window and while it is possible for me to keep track of them, I just want to know if there is an easy and clean way to get the parent layout.
EDIT2: Sorry, "easy and clean" was probably not the best way of putting. I meant using the Qt API.
EDIT3: I'm adding the widget to the layout like this:
QHBoxLayout* layout = new QHBoxLayout;
layout->addWidget(button);
I guess it is not easily possible then. Since a Widget can be technically contained in multiple layouts (a horizontal layout which is aligned inside a vertical layout, for instance).
Just remember that a QWidget's parent does not change if it is aligned in a layout.
You possibly have to keep track of that yourself, then.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With