qstackedwidget - container widget for vertically stacked widgets

Name

qstackedwidget — container widget for vertically stacked widgets. Similar to qtabwidget

Syntax

qstackedwidget [ parent ]

Description

The qstackedwidget command creates a QStackedWidget object. This container widget has the ability to stack child widgets on top of each other like pages in a book. It is similar to a qtabwidget but without the tabs. The widgets to be stacked are created separately and added using the qaddwidget command.

Only one widget at a time is visible in the QWidgetStack. To select which one, invoke the qsetcurrentwidget command with the widget id as argument.

The widgets that are to be stacked should not be added to a layout.

Arguments

parent

The parent widget. This argument is rarely needed since adding the QStackedWidget to a layout will set the parent correctly.

Examples

Ex.1: QStackedWidget

# Window
set w [qwidget ]
qsetwindowtitle QStackedWidget

# Create layout to contain stack and buttons
set layout [qvboxlayout $w]

# Create stacked widget and add to layout
set stackedwidget [qstackedwidget]
qaddwidget $layout $stackedwidget

# Create two editors and add to stack
set editor1 [qtextedit]
qsettext "Editor 1"
qaddwidget $stackedwidget $editor1

set editor2 [qtextedit]
qsettext "Editor 2"
qaddwidget $stackedwidget $editor2

# Create two buttons that sets current page
set b1 [qpushbutton "First page" "qsetcurrentwidget $stackedwidget $editor1"]
qaddwidget $layout $b1

set b2 [qpushbutton "Second page" "qsetcurrentwidget $stackedwidget $editor2"]
qaddwidget $layout $b2

qshow $w

Example QStackedWidget shows a QStackedWidget with two pages. Each page contains a texteditor of type QTextEdit added with the qaddwidget command. To switch between the pages two buttons are created, one for each page. When pushed they call qsetcurrentwidget, providing the desired visible widget as argument.