HomeHome

ClassesAnnotated - TreeFunctionsHomeStructure

QDialog Class Reference


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

#include <qdialog.h>

Inherits QWidget.

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

List of all member functions.

Public Members

Protected Members

Protected Slots

Properties

TypeNameREADWRITEOptions
boolsizeGripEnabledisSizeGripEnabledsetSizeGripEnabled 

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). The only way to set modality is by using the constructor, and the default is modelessness. For modal dialog, it's generally better to call exec() than show; exec() returns when the dialog has been closed and has a useful return value (see below).

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.

Examples: i18n/main.cpp


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.

QDialog::~QDialog ()

Destructs the QDialog, deleting all its children.

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

Hides the dialog and sets the result code to Accepted.

void QDialog::closeEvent ( QCloseEvent * e ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

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.

At some future date, this function will probably close the dialog instead of hiding it. It currently calls hide() in order to avoid breaking a large number of programs that reimplement closeEvent().

See also accept() and reject().

Reimplemented in QFileDialog.

int QDialog::exec ()

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

If the dialog is modeless, the behaviour of this function is undefined.

See also show() and result().

Examples: wizard/main.cpp i18n/main.cpp

QWidgetQDialog::extension () const

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

See also setExtension().

void QDialog::hide () [virtual]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

bool QDialog::isSizeGripEnabled () const

Returns TRUE if the QDialog has a QSizeGrip in the bottom right of the dialog, and FALSE if it does not.

See also setSizeGripEnabled().

void QDialog::keyPressEvent ( QKeyEvent * e ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

QSize QDialog::minimumSizeHint () const [virtual]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

void QDialog::move ( const QPoint & p )

Reimplemented for internal reasons; the API is not affected.

void QDialog::move ( int x, int y ) [virtual]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

Qt::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.

void QDialog::resize ( const QSize & s )

Reimplemented for internal reasons; the API is not affected.

Examples: tabdialog/main.cpp

void QDialog::resize ( int w, int h ) [virtual]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

void QDialog::resizeEvent ( QResizeEvent * ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

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::setGeometry ( const QRect & r ) [virtual]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

void QDialog::setGeometry ( int x, int y, int w, int h ) [virtual]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

void QDialog::setResult ( int ) [protected]

Sets the result code of the dialog.

void QDialog::setSizeGripEnabled ( bool enabled )

Enables or disables the QSizeGrip in the bottom right of the dialog. By default, the size grip is disabled.

See also isSizeGripEnabled().

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 work 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

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().

QSize QDialog::sizeHint () const [virtual]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.


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 2.2.1