Chapter 6. Using Layout Managers

So far, we have laid out our widgets in a very basic manner. We have set absolute positions and sizes with QWidget::resize and QWidget::move() or QWidget::setGeometry(), and we have specified the position within the parent and the size at which a widget should be shown. This process is generally not desirable. It makes the window that contains the widgets (often a dialog box) look bad when it is resized. If the size of this window is increased, an empty space will appear at the right and lower borders of the window because the widgets stay at their fixed positions and do not fill the newly available space. If, on the other hand, the size of the window is decreased, some widgets will not be visible any longer, or the window might appear incomplete. Again, this occurs because the widgets do not occupy less space and use less intrawidget space to accommodate the smaller parent window.

Another disadvantage comes from internationalization. When you prepare your program to display text in different languages, on-screen text in different languages are rarely the same size. If you design your dialog boxes with English labels and then have your application translated into a language such as Finnish, in which the average word length is long, the text will probably not fit into the allocated space.

Layout Manager Basics

The solution to these two problems is geometry management, also called layout management. When using geometry management, sizes and positions ...

Get Programming with Qt, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.