Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Parent Layout in Qt

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);

like image 722
Austin Avatar asked Mar 09 '10 14:03

Austin


1 Answers

(Updated answer)

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.

like image 180
BastiBen Avatar answered Oct 05 '22 04:10

BastiBen