Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt : what is the difference between layout and widget?

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?

like image 883
Łukasz Lew Avatar asked Apr 09 '10 16:04

Łukasz Lew


People also ask

What is layout in Qt?

The Qt layout system provides a simple and powerful way of automatically arranging child widgets within a widget to ensure that they make good use of the available space.

What is widget in Qt?

Widgets are the primary elements for creating user interfaces in Qt. Widgets can display data and status information, receive user input, and provide a container for other widgets that should be grouped together. A widget that is not embedded in a parent widget is called a window.

What is grid layout in Qt Designer?

The Grid LayoutComplex form layouts can be created by placing objects in a grid layout. This kind of layout gives the form designer much more freedom to arrange widgets on the form, but can result in a much less flexible layout.

What is a dock widget?

Detailed Description. QDockWidget provides the concept of dock widgets, also know as tool palettes or utility windows. Dock windows are secondary windows placed in the dock widget area around the central widget in a QMainWindow.


1 Answers

QWidget has built in support for layouts through the layout() and setLayout(...) 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 with setLayout(), 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.

like image 147
Kaleb Pederson Avatar answered Oct 08 '22 14:10

Kaleb Pederson