Classes - Annotated - Tree - Functions - Home - Structure

QDialog Class Reference

The QDialog class is the base class of dialog windows. More...

#include <qdialog.h>

Inherits QWidget.

Inherited by QColorDialog, QErrorMessage, QFileDialog, QFontDialog, QInputDialog, QMessageBox, QPrintDialog, QProgressDialog, QTabDialog and QWizard.

List of all member functions.

Public Members

Public Slots

Properties

Protected Members

Protected Slots


Detailed Description

The QDialog class is the base class of dialog windows.

A dialog window is a top-level window used for short-term tasks and brief communications with the user. QDialog offers mechanisms such as modality, default buttons, extensibility and a result value.

Modality means that the dialog blocks input to other windows: The user has to finish interacting with the dialog and close it before resuming work with the other window(s). You achieve this by calling exec() rather than show(); exec() returns when the dialog has been closed and has a useful return value (see below). Alternatively, you can request modality in the constructor. In that case, the dialog will always block input to other windows when being visible.

The default button is the button that's pressed when the user presses Enter or Return, to accept the things done using this dialog and close it. QDialog uses QPushButton::autoDefault(), QPushButton::isDefault() and QPushButton::setDefault() to make Enter or Return map to the right button at any time.

Extensibility is the ability to show more or less of the dialog. Typically, the dialog starts out small, has a "More" button, and when the user clicks "More", the dialog becomes bigger, and shows some less-used options. QDialog supports this using setExtension(), setOrientation() and showExtension().

Since dialogs typically tend to have result value (pressing Enter/Return maps to one value and pressing Escape to the other), QDialog supports that. A dialog can finish by calling the slots accept() or reject(), and exec() returns that result.

Note that QDialog uses the parent widget a bit differently from other classes in Qt. A dialog is always a top-level widget, but if it has a parent, its default location is on top of the parent, it shares taskbar entry with its parent, and there are some minor details.

QDialog also can provide a QSizeGrip in its lower-right corner. If you want that, call setSizeGripEnabled( TRUE ).

See also QTabDialog, QWidget, QSemiModal and GUI Design Handbook: Dialogs, Standard..


Member Function Documentation

QDialog::QDialog ( QWidget * parent = 0, const char * name = 0, bool modal = FALSE, WFlags f = 0 )

Constructs a dialog named name, which has a parent widget parent.

The dialog is modal (blocks input to other windows) if modal is TRUE, and modeless if modal is FALSE (this is the default).

The widget flags f are sent to the QWidget constructor, as usual.

If you e.g. don't want a What's this button in the titlebar of the dialog, pass WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu here.

We recommend always passing a parent.

See also QWidget::setWFlags and Qt::WidgetFlags.

QDialog::~QDialog ()

Destroys the QDialog, deleting all its children.

void QDialog::accept () [virtual protected slot]

Hides the dialog and sets the result code to Accepted.

void QDialog::done ( int r ) [virtual protected slot]

Hides the (modal) dialog and sets its result code to r. This uses the local event loop to finish and exec() to return r.

If the dialog has the WDestructiveClose flag set, done() also deletes the dialog. If the dialog is the applications's main widget, the application quits.

See also accept(), reject(), QApplication::mainWidget() and QApplication::quit().

Example: movies/main.cpp.

int QDialog::exec () [slot]

Starts the dialog, waits, and returns the result code when it is done.

A dialog started with exec() is always modal, i.e. the user has to finish interacting with the dialog and close it before resuming work with the other window(s).

If you want to show a non-modal dialog, call show().

See also show() and result().

Examples: i18n/main.cpp, qdir/qdir.cpp, showimg/showimg.cpp and wizard/main.cpp.

QWidget * QDialog::extension () const

Returns the dialog's extension or 0 if no extension has been defined.

See also setExtension().

bool QDialog::isSizeGripEnabled () const

Returns TRUE whether the size grip is enabled, otherwise returns FALSE. See the "sizeGripEnabled" property for details.

Orientation QDialog::orientation () const

Returns the extension direction of the dialog.

See also setOrientation().

void QDialog::reject () [virtual protected slot]

Hides the dialog and sets the result code to Rejected.

int QDialog::result () const

Returns the result code of the dialog.

void QDialog::setExtension ( QWidget * extension )

Sets extension to be the dialog's extension, or deletes the extensions if extension is 0.

The dialogs takes over ownership of the extension. Any previously set extension is deleted.

This function can only be called while the dialog is hidden.

See also showExtension(), setOrientation() and extension().

void QDialog::setOrientation ( Orientation orientation )

Sets the dialog to display its extension to the right of the main are if orientation is Horizonal, and to display it below the main area if orientation is Vertical.

See also orientation() and setExtension().

void QDialog::setResult ( int r ) [protected]

Sets the result code of the dialog.

void QDialog::setSizeGripEnabled ( bool )

Sets whether the size grip is enabled. See the "sizeGripEnabled" property for details.

void QDialog::show () [virtual]

Shows the dialog box on the screen, as QWidget::show(), and selects a suitable position and size if none has been specified yet.

Warning:

In Qt 2.x, calling show() on a modal dialog enters a local event loop, and works like exec(), but not returning the result code exec() returns. Trolltech has always warned against doing this.

In Qt 3.0 and later, calling show() on a modal dialog will return immediately, not enter a local event loop. The dialog will of course be modal.

See also exec().

Examples: movies/main.cpp, showimg/showimg.cpp, sql/overview/form1/main.cpp and tabdialog/main.cpp.

Reimplemented from QWidget.

void QDialog::showExtension ( bool showIt ) [protected slot]

Extends the dialog to show its extension if showIt is TRUE and hides it else.

This slot is usually connected to the QButton::toggled() signal of a QPushButton.

If the dialog is not visible, nothing happens.

See also show(), setExtension() and setOrientation().


Property Documentation

bool sizeGripEnabled

This property holds whether the size grip is enabled.

A QSizeGrip is placed in the bottom right corner of the dialog when this property is enabled. By default, the size grip is disabled.

Set this property's value with setSizeGripEnabled() and get this property's value with isSizeGripEnabled().


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2000 Trolltech, all rights reserved.


Copyright © 2000 TrolltechTrademarks
Qt version main-beta1