<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- /tmp/qt-3.0-reggie-28534/qt-x11-free-3.0.2/src/dialogs/qdialog.cpp:57 --> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>QDialog Class</title> <style type="text/css"><!-- h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } body { background: #ffffff; color: black; } --></style> </head> <body> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr bgcolor="#E5E5E5"> <td valign=center> <a href="index.html"> <font color="#004faf">Home</font></a> | <a href="classes.html"> <font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"> <font color="#004faf">Main Classes</font></a> | <a href="annotated.html"> <font color="#004faf">Annotated</font></a> | <a href="groups.html"> <font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"> <font color="#004faf">Functions</font></a> </td> <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QDialog Class Reference</h1> <p>The QDialog class is the base class of dialog windows. <a href="#details">More...</a> <p><tt>#include <<a href="qdialog-h.html">qdialog.h</a>></tt> <p>Inherits <a href="qwidget.html">QWidget</a>. <p>Inherited by <a href="qcolordialog.html">QColorDialog</a>, <a href="qerrormessage.html">QErrorMessage</a>, <a href="qfiledialog.html">QFileDialog</a>, <a href="qfontdialog.html">QFontDialog</a>, <a href="qinputdialog.html">QInputDialog</a>, <a href="qmessagebox.html">QMessageBox</a>, <a href="qprogressdialog.html">QProgressDialog</a>, <a href="qtabdialog.html">QTabDialog</a> and <a href="qwizard.html">QWizard</a>. <p><a href="qdialog-members.html">List of all member functions.</a> <h2>Public Members</h2> <ul> <li><div class=fn><a href="#QDialog"><b>QDialog</b></a> ( QWidget * parent = 0, const char * name = 0, bool modal = FALSE, WFlags f = 0 )</div></li> <li><div class=fn><a href="#~QDialog"><b>~QDialog</b></a> ()</div></li> <li><div class=fn>enum <a href="#DialogCode-enum"><b>DialogCode</b></a> { Rejected, Accepted }</div></li> <li><div class=fn>int <a href="#result"><b>result</b></a> () const</div></li> <li><div class=fn>virtual void <a href="#show"><b>show</b></a> ()</div></li> <li><div class=fn>void <a href="#setOrientation"><b>setOrientation</b></a> ( Orientation orientation )</div></li> <li><div class=fn>Orientation <a href="#orientation"><b>orientation</b></a> () const</div></li> <li><div class=fn>void <a href="#setExtension"><b>setExtension</b></a> ( QWidget * extension )</div></li> <li><div class=fn>QWidget * <a href="#extension"><b>extension</b></a> () const</div></li> <li><div class=fn>void <a href="#setSizeGripEnabled"><b>setSizeGripEnabled</b></a> ( bool )</div></li> <li><div class=fn>bool <a href="#isSizeGripEnabled"><b>isSizeGripEnabled</b></a> () const</div></li> </ul> <h2>Public Slots</h2> <ul> <li><div class=fn>int <a href="#exec"><b>exec</b></a> ()</div></li> </ul> <h2>Properties</h2> <ul> <li><div class=fn>bool <a href="#sizeGripEnabled-prop"><b>sizeGripEnabled</b></a> - whether the size grip is enabled</div></li> </ul> <h2>Protected Members</h2> <ul> <li><div class=fn>void <a href="#setResult"><b>setResult</b></a> ( int i )</div></li> </ul> <h2>Protected Slots</h2> <ul> <li><div class=fn>virtual void <a href="#done"><b>done</b></a> ( int r )</div></li> <li><div class=fn>virtual void <a href="#accept"><b>accept</b></a> ()</div></li> <li><div class=fn>virtual void <a href="#reject"><b>reject</b></a> ()</div></li> <li><div class=fn>void <a href="#showExtension"><b>showExtension</b></a> ( bool showIt )</div></li> </ul> <hr><a name="details"></a><h2>Detailed Description</h2> The QDialog class is the base class of dialog windows. <p> <p> A dialog window is a top-level window mostly used for short-term tasks and brief communications with the user. QDialogs may be modal or modeless. QDialogs can have <a href="#default">default buttons</a>, support <a href="#extensibility">extensibility</a> and may provide a <a href="#return">return value</a>. QDialogs can have a <a href="qsizegrip.html">QSizeGrip</a> in their lower-right corner, using <a href="#setSizeGripEnabled">setSizeGripEnabled</a>(). <p> Note that QDialog uses the parent widget slightly differently from other classes in Qt. A dialog is always a top-level widget, but if it has a parent, its default location is centered on top of the parent. It will also share the parent's taskbar entry, for example. <p> There are three kinds of dialog that are useful: <ol type=1> <li> A <b>modal</b> dialog is a dialog that blocks input to other visible windows in the same application: users must finish interacting with the dialog and close it before they can access any other window in the application. Modal dialogs have their own local event loop. Dialogs which are used to request a filename from the user or which are used to set application preferences are usually modal. Call <a href="#exec">exec</a>() to display a modal dialog. When the user closes the dialog, exec() will provide a useful <a href="#return">return value</a>, and the flow of control will follow on from the exec() call at this time. Typically we connect a default button, e.g. "OK", to the <a href="#accept">accept</a>() slot and a "Cancel" button to the <a href="#reject">reject</a>() slot, to get the dialog to close and return the appropriate value. Alternatively you can connect to the <a href="#done">done</a>() slot, passing it <a href="#DialogCode-enum">Accepted</a> or <a href="#DialogCode-enum">Rejected</a>. <p> <li> A <b>non-modal</b> dialog is a dialog that operates independently of other windows in the same application. Find and replace dialogs in word-processors are often modeless to allow the user to interact with both the application's main window and the dialog. Call <a href="#show">show</a>() to display a non-modal dialog. show() returns immediately so the flow of control will continue in the calling code. In practice you will often call show() and come to the end of the function in which show() is called with control returning to the main event loop. <p> <li> <a name="semimodal">A "<b>semi-modal</b>" dialog is a modal dialog that returns control to the caller immediately. Semi-modal dialogs do not have their own event loop, so you will need to call <a href="qapplication.html#processEvents">QApplication::processEvents</a>() periodically to give the semi-modal dialog the opportunity to process its events. A progress dialog (e.g. <a href="qprogressdialog.html">QProgressDialog</a>) is an example, where you only want the user to be able to interact with the progress dialog, e.g. to cancel a long running operation, but need to actually carry out the operation. Semi-modal dialogs are displayed by setting the modal flag to TRUE and calling the <a href="#show">show</a>() function. </ol> <p> <a name="default"><b>Default button</b><br> A dialog's "default" button is the button that's pressed when the user presses Enter or Return. This button is used to signify that the user accepts the dialog's settings and wishes to close the dialog. Use <a href="qpushbutton.html#setDefault">QPushButton::setDefault</a>(), <a href="qpushbutton.html#isDefault">QPushButton::isDefault</a>() and <a href="qpushbutton.html#autoDefault">QPushButton::autoDefault</a>() to set and control the dialog's default button. <p> <a name="extensibility"><b>Extensibility</b><br> Extensibility is the ability to show the dialog in two ways: a partial dialog that shows the most commonly used options, and a full dialog that shows all the options. Typically an extensible dialog will initially appear as a partial dialog, but with a "More" button. If the user clicks the "More" button, the full dialog will appear. Extensibility is controlled with <a href="#setExtension">setExtension</a>(), <a href="#setOrientation">setOrientation</a>() and <a href="#showExtension">showExtension</a>(). <p> <a name="return"><b>Return value (modal dialogs)</b><br> Modal dialogs are often used in situations where a return value is required; for example to indicate whether the user pressed OK or Cancel. A dialog can be closed by calling the <a href="#accept">accept</a>() or the <a href="#reject">reject</a>() slots, and <a href="#exec">exec</a>() will return <a href="#DialogCode-enum">Accepted</a> or <a href="#DialogCode-enum">Rejected</a> as appropriate. After the exec() call has returned the result is available from <a href="#result">result</a>(). Note that if the WDestructiveClose flag is set, then when accept() returns the dialog is deleted. <p> <a name="examples"><b>Examples</b><br> <p> A modal dialog. <p> <pre> <a href="qfiledialog.html">QFileDialog</a> *dlg = new <a href="qfiledialog.html">QFileDialog</a>( workingDirectory, <a href="qstring.html#QString-null">QString::null</a>, 0, 0, TRUE ); <a name="x32"></a> dlg-><a href="qwidget.html#setCaption">setCaption</a>( QFileDialog::<a href="qobject.html#tr">tr</a>( "Open" ) ); <a name="x30"></a> dlg-><a href="qfiledialog.html#setMode">setMode</a>( QFileDialog::ExistingFile ); <a href="qstring.html">QString</a> result; <a name="x28"></a> if ( dlg-><a href="#exec">exec</a>() == QDialog::<a href="#DialogCode-enum">Accepted</a> ) { <a name="x29"></a> result = dlg-><a href="qfiledialog.html#selectedFile">selectedFile</a>(); <a name="x31"></a> workingDirectory = dlg-><a href="qfiledialog.html#url">url</a>(); } delete dlg; return result; </pre> <p> A modeless dialog. After the <a href="#show">show</a>() call, control returns to the main event loop. <pre> int main( int argc, char **argv ) { <a href="qapplication.html">QApplication</a> a( argc, argv ); </pre><pre> int scale = 10; </pre><pre> LifeDialog *life = new LifeDialog( scale ); <a name="x35"></a> a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( life ); <a name="x36"></a> life-><a href="qwidget.html#setCaption">setCaption</a>("Qt Example - Life"); life-><a href="qwidget.html#show">show</a>(); </pre><pre> <a name="x34"></a> return a.<a href="qapplication.html#exec">exec</a>(); } </pre> <p> See the <a href="qprogressdialog.html">QProgressDialog</a> documentation for an example of a semi-modal dialog. <p> <p>See also <a href="qtabdialog.html">QTabDialog</a>, <a href="qwidget.html">QWidget</a>, <a href="qprogressdialog.html">QProgressDialog</a>, <a href="guibooks.html#fowler">GUI Design Handbook: Dialogs, Standard</a>, <a href="abstractwidgets.html">Abstract Widget Classes</a> and <a href="dialogs.html">Dialog Classes</a>. <hr><h2>Member Type Documentation</h2> <h3 class=fn><a name="DialogCode-enum"></a>QDialog::DialogCode</h3> <p> The value returned by a modal dialog. <ul> <li><tt>QDialog::Accepted</tt> <li><tt>QDialog::Rejected</tt> </ul><p> <hr><h2>Member Function Documentation</h2> <h3 class=fn><a name="QDialog"></a>QDialog::QDialog ( <a href="qwidget.html">QWidget</a> * parent = 0, const char * name = 0, bool modal = FALSE, WFlags f = 0 ) </h3> Constructs a dialog called <em>name</em>, with parent <em>parent</em>. <p> If <em>modal</em> is FALSE (the default), the dialog is modeless and should be displayed with <a href="#show">show</a>(). If <em>modal</em> is TRUE and the dialog is displayed with <a href="#exec">exec</a>(), the dialog is modal, i.e. blocks input to other windows. If <em>modal</em> is TRUE and the dialog is displayed show(), the dialog is semi-modal. <p> The <a href="qt.html#WidgetFlags">widget flags</a> <em>f</em> are passed on to the <a href="qwidget.html">QWidget</a> constructor. <p> If, for example, you don't want a What's this button in the titlebar of the dialog, pass WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu in <em>f</em>. <p> We recommend that you always pass a non-null parent. <p> <p>See also <a href="qwidget.html#setWFlags">QWidget::setWFlags</a>() and <a href="qt.html#WidgetFlags-enum">Qt::WidgetFlags</a>. <h3 class=fn><a name="~QDialog"></a>QDialog::~QDialog () </h3> Destroys the QDialog, deleting all its children. <h3 class=fn>void <a name="accept"></a>QDialog::accept ()<tt> [virtual protected slot]</tt> </h3> Hides the modal dialog and sets the result code to <a href="#DialogCode-enum">Accepted</a>. <p>See also <a href="#reject">reject</a>() and <a href="#done">done</a>(). <h3 class=fn>void <a name="done"></a>QDialog::done ( int r )<tt> [virtual protected slot]</tt> </h3> Hides the modal dialog and sets its result code to <em>r</em>. This uses the local event loop to finish, and <a href="#exec">exec</a>() to return <em>r</em>. <p> If the dialog has the <a href="qt.html#WidgetFlags-enum">WDestructiveClose</a> flag set, <a href="#done">done</a>() also deletes the dialog. If the dialog is the applications's main widget, the application terminates. <p> <p>See also <a href="#accept">accept</a>(), <a href="#reject">reject</a>(), <a href="qapplication.html#mainWidget">QApplication::mainWidget</a>() and <a href="qapplication.html#quit">QApplication::quit</a>(). <p>Example: <a href="movies-example.html#x1081">movies/main.cpp</a>. <h3 class=fn>int <a name="exec"></a>QDialog::exec ()<tt> [slot]</tt> </h3> Executes a modal dialog. Control passes to the dialog until the user closes it, at which point the local event loop finishes and the function returns with the <a href="#DialogCode-enum">DialogCode</a> result. Users will not be able to interact with any other window in the same application until they close this dialog. For a modeless or semi-modal dialog use <a href="#show">show</a>(). <p> <p>See also <a href="#show">show</a>() and <a href="#result">result</a>(). <p>Examples: <a href="i18n-example.html#x1371">i18n/main.cpp</a>, <a href="qdialog.html#x28">network/networkprotocol/view.cpp</a>, <a href="qdir-example.html#x770">qdir/qdir.cpp</a>, <a href="showimg-example.html#x416">showimg/showimg.cpp</a> and <a href="wizard-example.html#x154">wizard/main.cpp</a>. <h3 class=fn><a href="qwidget.html">QWidget</a> * <a name="extension"></a>QDialog::extension () const </h3> Returns the dialog's extension or 0 if no extension has been defined. <p> <p>See also <a href="#setExtension">setExtension</a>(). <h3 class=fn>bool <a name="isSizeGripEnabled"></a>QDialog::isSizeGripEnabled () const </h3><p>Returns TRUE if the size grip is enabled; otherwise returns FALSE. See the <a href="qdialog.html#sizeGripEnabled-prop">"sizeGripEnabled"</a> property for details. <h3 class=fn><a href="qt.html#Orientation-enum">Orientation</a> <a name="orientation"></a>QDialog::orientation () const </h3> Returns the dialog's extension orientation. <p> <p>See also <a href="#setOrientation">setOrientation</a>(). <h3 class=fn>void <a name="reject"></a>QDialog::reject ()<tt> [virtual protected slot]</tt> </h3> Hides the modal dialog and sets the result code to <a href="#DialogCode-enum">Rejected</a>. <p>See also <a href="#accept">accept</a>() and <a href="#done">done</a>(). <h3 class=fn>int <a name="result"></a>QDialog::result () const </h3> <p> Returns the modal dialog's result code, <a href="#DialogCode-enum">Accepted</a> or <a href="#DialogCode-enum">Rejected</a>. <h3 class=fn>void <a name="setExtension"></a>QDialog::setExtension ( <a href="qwidget.html">QWidget</a> * extension ) </h3> Sets the widget, <em>extension</em>, to be the dialog's extension, deleting any previous extension. The dialog takes ownership of the extension. Note that if 0 is passed any existing extension will be deleted. <p> This function must only be called while the dialog is hidden. <p> <p>See also <a href="#showExtension">showExtension</a>(), <a href="#setOrientation">setOrientation</a>() and <a href="#extension">extension</a>(). <h3 class=fn>void <a name="setOrientation"></a>QDialog::setOrientation ( <a href="qt.html#Orientation-enum">Orientation</a> orientation ) </h3> If <em>orientation</em> is <a href="qt.html#Orientation-enum">Horizontal</a>, the extension will be displayed to the right of the dialog's main area. If <em>orientation</em> is <a href="qt.html#Orientation-enum">Vertical</a>, the extension will be displayed below the dialog's main area. <p> <p>See also <a href="#orientation">orientation</a>() and <a href="#setExtension">setExtension</a>(). <h3 class=fn>void <a name="setResult"></a>QDialog::setResult ( int i )<tt> [protected]</tt> </h3> <p> Sets the modal dialog's result code to <em>i</em>. <h3 class=fn>void <a name="setSizeGripEnabled"></a>QDialog::setSizeGripEnabled ( bool ) </h3><p>Sets whether the size grip is enabled. See the <a href="qdialog.html#sizeGripEnabled-prop">"sizeGripEnabled"</a> property for details. <h3 class=fn>void <a name="show"></a>QDialog::show ()<tt> [virtual]</tt> </h3> Shows a modeless or semi-modal dialog. Control returns immediately to the calling code. <p> The dialog does not have a local event loop so you must call <a href="qapplication.html#processEvents">QApplication::processEvents</a>() periodically to give the dialog the opportunity to process its events. <p> The dialog will be <a href="#semimodal">semi-modal</a> if the modal flag was set to TRUE in the constructor. <p> <b>Warning:</b> <p> In Qt 2.x, calling <a href="#show">show</a>() on a modal dialog enters a local event loop, and works like <a href="#exec">exec</a>(), but doesn't return the result code exec() returns. Trolltech has always warned that doing this is unwise. <p> <p>See also <a href="#exec">exec</a>(). <p>Examples: <a href="movies-example.html#x1082">movies/main.cpp</a>, <a href="showimg-example.html#x417">showimg/showimg.cpp</a>, <a href="sql.html#x2334">sql/overview/form1/main.cpp</a> and <a href="tabdialog-example.html#x392">tabdialog/main.cpp</a>. <p>Reimplemented from <a href="qwidget.html#show">QWidget</a>. <h3 class=fn>void <a name="showExtension"></a>QDialog::showExtension ( bool showIt )<tt> [protected slot]</tt> </h3> If <em>showIt</em> is TRUE, the dialog's extension is shown; otherwise the extension is hidden. <p> This slot is usually connected to the <a href="qbutton.html#toggled">QButton::toggled</a>() signal of a <a href="qpushbutton.html">QPushButton</a>. <p> If the dialog is not visible, or has no extension, nothing happens. <p> <p>See also <a href="#show">show</a>(), <a href="#setExtension">setExtension</a>() and <a href="#setOrientation">setOrientation</a>(). <hr><h2>Property Documentation</h2> <h3 class=fn>bool <a name="sizeGripEnabled-prop"></a>sizeGripEnabled</h3> <p>This property holds whether the size grip is enabled. <p>A <a href="qsizegrip.html">QSizeGrip</a> is placed in the bottom right corner of the dialog when this property is enabled. By default, the size grip is disabled. <p>Set this property's value with <a href="#setSizeGripEnabled">setSizeGripEnabled</a>() and get this property's value with <a href="#isSizeGripEnabled">isSizeGripEnabled</a>(). <!-- eof --> <hr><p> This file is part of the <a href="index.html">Qt toolkit</a>. Copyright © 1995-2001 <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center> <table width=100% cellspacing=0 border=0><tr> <td>Copyright © 2001 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a> <td align=right><div align=right>Qt version 3.0.2</div> </table></div></address></body> </html>