Widget Stacks

Another useful widget for managing layouts is QWidgetStack. This widget contains a set of child widgets, or "pages", and shows only one at a time, hiding the others from the user. The pages are numbered from 0. If we want to make a specific child widget visible, we can call raiseWidget() with either a page number or a pointer to the child widget.

The QWidgetStack itself is invisible and provides no intrinsic means for the user to change page. The small arrows and the dark gray frame in Figure 6.7 are provided by Qt Designer to make the QWidgetStack easier to design with.

Figure 6.7. QWidgetStack


The Configure dialog shown in Figure 6.8 is an example that uses QWidgetStack. The dialog consists of a QListBox on the left and a QWidgetStack on the right. Each item in the QListBox corresponds to a different page in the QWidgetStack. Forms like this are very easy to create using Qt Designer:

  1. Create a new form based on the "Dialog" or the "Widget" template.
  2. Add a list box and a widget stack to the form.
  3. Fill each widget stack page with child widgets and layouts. (To create a new page, right-click and choose Add Page; to switch pages, click the tiny left or right arrow located at the top-right of the widget stack.)
  4. Lay the widgets out side by side using a horizontal layout.
  5. Connect the list box's highlighted(int) signal to the widget stack's raiseWidget(int) slot.
  6. Set the value of the list box's currentItem property to 0.

Figure 6.8. The Configure dialog


Since we have implemented page-switching using predefined signals and slots, the dialog will exhibit the correct page-switching behavior when previewed in Qt Designer.

Part I: Basic Qt

Getting Started

Creating Dialogs

Creating Main Windows

Implementing Application Functionality

Creating Custom Widgets

Part II: Intermediate Qt

Layout Management

Event Processing

2D and 3D Graphics

Drag and Drop


Container Classes





Providing Online Help


Platform-Specific Features

C++ GUI Programming with Qt 3
C++ GUI Programming with Qt 3
ISBN: 0131240722
EAN: 2147483647
Year: 2006
Pages: 140

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net