Book Image

Application Development with Qt Creator - Second Edition

Book Image

Application Development with Qt Creator - Second Edition

Overview of this book

Table of Contents (20 chapters)
Application Development with Qt Creator Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Managing the widget layout with layouts


Qt Widgets includes a robust layout system to control the presentation of widgets on the display. In Qt Creator Designer, you can pick from the following layouts:

  • QBoxLayout: This lays out its view children horizontally or vertically

  • QHBoxLayout: This lays out its view children horizontally

  • QVBoxLayout: This lays out its view children vertically

  • QFormLayout: This lays out pairs of widgets (such as labels and textboxes) side by side and then tiles those pairs vertically, giving the appearance of a form

  • QGridLayout: This lays out widgets in a grid

  • QStackedLayout: This shows only a single widget at a time

Using one of these layouts is easy: simply choose the appropriate layout in Qt Creator Designer and drag it to the widget or window you're building. If you're constructing a hierarchy of widgets in the code, you add the widgets to the layout and set the parent widget's layout, like this:

QWidget *window = new QWidget();
QPushButton *button1 = new QPushButton...