I thought that layout is just a widget that keeps more widgets inside.
But now I find that I can’t add it to other widgets using addWidget.
For instance how to add a layout to QSplitter?
I thought that layout is just a widget that keeps more widgets inside. But
Share
QWidget has built in support for layouts through the
layout()andsetLayout(...)functions. The layout object controls the positioning of different child widgets that may be added to the layout. In addition, it makes sure to correctly size its parent widget based on the constraints specified. If the layout does not yet have a parent widget, then as soon as the layout is attached to a widget withsetLayout(), it will set the size of that parent widget.But, some widgets are more like a layout manager than a widget, such as QSplitter and QTabWidget. Consider, for example, QSplitter. Although a single widget, it presents two different areas that may be worked with. In this case, a single layout manager for two different areas doesn’t really make sense. Like QSplitter, QTabWidget has some behaviors which make a single layout not only unnecessary but not useful.
I think it’s the above melding of layout and widget that makes the separation of layout and widget sometimes confusing.