1
<?xml version="1.0" encoding="iso-8859-1"?>
3
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/gui/dialogs/qinputdialog.cpp -->
7
<title>Qt 4.0: QInputDialog Class Reference</title>
8
<style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
9
a:link { color: #004faf; text-decoration: none }
10
a:visited { color: #672967; text-decoration: none }
11
td.postheader { font-family: sans-serif }
12
tr.address { font-family: sans-serif }
13
body { background: #ffffff; color: black; }</style>
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
19
<td width="1"> </td><td class="postheader" 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>
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QInputDialog Class Reference</h1>
21
<p>The QInputDialog class provides a simple convenience dialog to get a single value from the user. <a href="#details">More...</a></p>
22
<pre>#include <QInputDialog></pre><p>Part of the <a href="qtgui.html">QtGui</a> module.</p>
23
<p>Inherits <a href="qdialog.html">QDialog</a>.</p>
25
<li><a href="qinputdialog-members.html">List of all members, including inherited members</a></li>
26
<li><a href="qinputdialog-qt3.html">Qt 3 support members</a></li>
28
<a name="static-public-members"></a>
29
<h3>Static Public Members</h3>
31
<li><div class="fn"/>double <b><a href="qinputdialog.html#getDouble">getDouble</a></b> ( QWidget * <i>parent</i>, const QString & <i>title</i>, const QString & <i>label</i>, double <i>value</i> = 0, double <i>minValue</i> = -2147483647, double <i>maxValue</i> = 2147483647, int <i>decimals</i> = 1, bool * <i>ok</i> = 0, Qt::WFlags <i>f</i> = 0 )</li>
32
<li><div class="fn"/>int <b><a href="qinputdialog.html#getInteger">getInteger</a></b> ( QWidget * <i>parent</i>, const QString & <i>title</i>, const QString & <i>label</i>, int <i>value</i> = 0, int <i>minValue</i> = -2147483647, int <i>maxValue</i> = 2147483647, int <i>step</i> = 1, bool * <i>ok</i> = 0, Qt::WFlags <i>f</i> = 0 )</li>
33
<li><div class="fn"/>QString <b><a href="qinputdialog.html#getItem">getItem</a></b> ( QWidget * <i>parent</i>, const QString & <i>title</i>, const QString & <i>label</i>, const QStringList & <i>list</i>, int <i>current</i> = 0, bool <i>editable</i> = true, bool * <i>ok</i> = 0, Qt::WFlags <i>f</i> = 0 )</li>
34
<li><div class="fn"/>QString <b><a href="qinputdialog.html#getText">getText</a></b> ( QWidget * <i>parent</i>, const QString & <i>title</i>, const QString & <i>label</i>, QLineEdit::EchoMode <i>mode</i> = QLineEdit::Normal, const QString & <i>text</i> = QString(), bool * <i>ok</i> = 0, Qt::WFlags <i>f</i> = 0 )</li>
37
<li><div class="fn"/>4 static public members inherited from <a href="qwidget.html#static-public-members">QWidget</a></li>
38
<li><div class="fn"/>4 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
40
<h3>Additional Inherited Members</h3>
42
<li><div class="fn"/>2 properties inherited from <a href="qdialog.html#properties">QDialog</a></li>
43
<li><div class="fn"/>52 properties inherited from <a href="qwidget.html#properties">QWidget</a></li>
44
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
45
<li><div class="fn"/>9 public functions inherited from <a href="qdialog.html#public-functions">QDialog</a></li>
46
<li><div class="fn"/>183 public functions inherited from <a href="qwidget.html#public-functions">QWidget</a></li>
47
<li><div class="fn"/>28 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
48
<li><div class="fn"/>10 public functions inherited from <a href="qpaintdevice.html#public-functions">QPaintDevice</a></li>
49
<li><div class="fn"/>5 public slots inherited from <a href="qdialog.html#public-slots">QDialog</a></li>
50
<li><div class="fn"/>17 public slots inherited from <a href="qwidget.html#public-slots">QWidget</a></li>
51
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
52
<li><div class="fn"/>1 signal inherited from <a href="qwidget.html#signals">QWidget</a></li>
53
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
54
<li><div class="fn"/>39 protected functions inherited from <a href="qwidget.html#protected-functions">QWidget</a></li>
55
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
57
<a name="details"></a>
59
<h2>Detailed Description</h2>
60
<p>The QInputDialog class provides a simple convenience dialog to get a single value from the user.</p>
61
<p>The input value can be a string, a number or an item from a list. A label must be set to tell the user what they should enter.</p>
62
<p>Four static convenience functions are provided: <a href="qinputdialog.html#getText">getText</a>(), <a href="qinputdialog.html#getInteger">getInteger</a>(), <a href="qinputdialog.html#getDouble">getDouble</a>() and <a href="qinputdialog.html#getItem">getItem</a>(). All the functions can be used in a similar way, for example:</p>
64
QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
65
tr("User name:"), QLineEdit::Normal,
66
QDir::home().dirName(), &ok);
67
if (ok && !text.isEmpty())
68
textLabel->setText(text);</pre>
69
<p>The <tt>ok</tt> variable is set to true if the user clicks <b>OK</b>; otherwise it is set to false.</p>
70
<center><img src="images/inputdialogs.png" alt="Input Dialogs" /></center><p>The <a href="dialogs-standarddialogs.html">Standard Dialogs</a> example shows how to use QInputDialog as well as other built-in Qt dialogs.</p>
71
<p>See also <a href="qmessagebox.html">QMessageBox</a>.</p>
73
<h2>Member Function Documentation</h2>
74
<h3 class="fn"><a name="getDouble"></a>double QInputDialog::getDouble ( <a href="qwidget.html">QWidget</a> * <i>parent</i>, const <a href="qstring.html">QString</a> & <i>title</i>, const <a href="qstring.html">QString</a> & <i>label</i>, double <i>value</i> = 0, double <i>minValue</i> = -2147483647, double <i>maxValue</i> = 2147483647, int <i>decimals</i> = 1, bool * <i>ok</i> = 0, <a href="qt.html#WFlags-typedef">Qt::WFlags</a> <i>f</i> = 0 ) <tt> [static]</tt></h3>
75
<p>Static convenience function to get a floating point number from the user. <i>title</i> is the text which is displayed in the title bar of the dialog. <i>label</i> is the text which is shown to the user (it should say what should be entered). <i>value</i> is the default floating point number that the line edit will be set to. <i>minValue</i> and <i>maxValue</i> are the minimum and maximum values the user may choose, and <i>decimals</i> is the maximum number of decimal places the number may have.</p>
76
<p>If <i>ok</i> is non-null, *<i>ok</i> will be set to true if the user pressed OK and to false if the user pressed <b>Cancel</b>. The dialog's parent is <i>parent</i>. The dialog will be modal and uses the widget flags <i>f</i>.</p>
77
<p>This function returns the floating point number which has been entered by the user.</p>
78
<p>Use this static function like this:</p>
80
double d = QInputDialog::getDouble(this, tr("QInputDialog::getDouble()"),
81
tr("Amount:"), 37.56, -10000, 10000, 2, &ok);
83
doubleLabel->setText(QString("$%1").arg(d));</pre>
84
<p>See also <a href="qinputdialog.html#getText">getText</a>(), <a href="qinputdialog.html#getInteger">getInteger</a>(), and <a href="qinputdialog.html#getItem">getItem</a>().</p>
85
<h3 class="fn"><a name="getInteger"></a>int QInputDialog::getInteger ( <a href="qwidget.html">QWidget</a> * <i>parent</i>, const <a href="qstring.html">QString</a> & <i>title</i>, const <a href="qstring.html">QString</a> & <i>label</i>, int <i>value</i> = 0, int <i>minValue</i> = -2147483647, int <i>maxValue</i> = 2147483647, int <i>step</i> = 1, bool * <i>ok</i> = 0, <a href="qt.html#WFlags-typedef">Qt::WFlags</a> <i>f</i> = 0 ) <tt> [static]</tt></h3>
86
<p>Static convenience function to get an integer input from the user. <i>title</i> is the text which is displayed in the title bar of the dialog. <i>label</i> is the text which is shown to the user (it should say what should be entered). <i>value</i> is the default integer which the spinbox will be set to. <i>minValue</i> and <i>maxValue</i> are the minimum and maximum values the user may choose, and <i>step</i> is the amount by which the values change as the user presses the arrow buttons to increment or decrement the value.</p>
87
<p>If <i>ok</i> is non-null *<i>ok</i> will be set to true if the user pressed <b>OK</b> and to false if the user pressed <b>Cancel</b>. The dialog's parent is <i>parent</i>. The dialog will be modal and uses the widget flags <i>f</i>.</p>
88
<p>This function returns the integer which has been entered by the user.</p>
89
<p>Use this static function like this:</p>
91
int i = QInputDialog::getInteger(this, tr("QInputDialog::getInteger()"),
92
tr("Percentage:"), 25, 0, 100, 1, &ok);
94
integerLabel->setText(tr("%1%").arg(i));</pre>
95
<p>See also <a href="qinputdialog.html#getText">getText</a>(), <a href="qinputdialog.html#getDouble">getDouble</a>(), and <a href="qinputdialog.html#getItem">getItem</a>().</p>
96
<h3 class="fn"><a name="getItem"></a><a href="qstring.html">QString</a> QInputDialog::getItem ( <a href="qwidget.html">QWidget</a> * <i>parent</i>, const <a href="qstring.html">QString</a> & <i>title</i>, const <a href="qstring.html">QString</a> & <i>label</i>, const <a href="qstringlist.html">QStringList</a> & <i>list</i>, int <i>current</i> = 0, bool <i>editable</i> = true, bool * <i>ok</i> = 0, <a href="qt.html#WFlags-typedef">Qt::WFlags</a> <i>f</i> = 0 ) <tt> [static]</tt></h3>
97
<p>Static convenience function to let the user select an item from a string list. <i>title</i> is the text which is displayed in the title bar of the dialog. <i>label</i> is the text which is shown to the user (it should say what should be entered). <i>list</i> is the string list which is inserted into the combobox, and <i>current</i> is the number of the item which should be the current item. If <i>editable</i> is true the user can enter their own text; if <i>editable</i> is false the user may only select one of the existing items.</p>
98
<p>If <i>ok</i> is non-null <i>*a</i> ok will be set to true if the user pressed OK and to false if the user pressed <b>Cancel</b>. The dialog's parent is <i>parent</i>. The dialog will be modal and uses the widget flags <i>f</i>.</p>
99
<p>This function returns the text of the current item, or if <i>editable</i> is true, the current text of the combobox.</p>
100
<p>Use this static function like this:</p>
101
<pre> QStringList items;
102
items << tr("Spring") << tr("Summer") << tr("Fall") << tr("Winter");
105
QString item = QInputDialog::getItem(this, tr("QInputDialog::getItem()"),
106
tr("Season:"), items, 0, false, &ok);
107
if (ok && !item.isEmpty())
108
itemLabel->setText(item);</pre>
109
<p>See also <a href="qinputdialog.html#getText">getText</a>(), <a href="qinputdialog.html#getInteger">getInteger</a>(), and <a href="qinputdialog.html#getDouble">getDouble</a>().</p>
110
<h3 class="fn"><a name="getText"></a><a href="qstring.html">QString</a> QInputDialog::getText ( <a href="qwidget.html">QWidget</a> * <i>parent</i>, const <a href="qstring.html">QString</a> & <i>title</i>, const <a href="qstring.html">QString</a> & <i>label</i>, <a href="qlineedit.html#EchoMode-enum">QLineEdit::EchoMode</a> <i>mode</i> = QLineEdit::Normal, const <a href="qstring.html">QString</a> & <i>text</i> = QString(), bool * <i>ok</i> = 0, <a href="qt.html#WFlags-typedef">Qt::WFlags</a> <i>f</i> = 0 ) <tt> [static]</tt></h3>
111
<p>Static convenience function to get a string from the user. <i>title</i> is the text which is displayed in the title bar of the dialog. <i>label</i> is the text which is shown to the user (it should say what should be entered). <i>text</i> is the default text which is placed in the line edit. The <i>mode</i> is the echo mode the line edit will use. If <i>ok</i> is non-null <i>*a</i> ok will be set to true if the user pressed <b>OK</b> and to false if the user pressed <b>Cancel</b>. The dialog's parent is <i>parent</i>. The dialog will be modal and uses the widget flags <i>f</i>.</p>
112
<p>This function returns the text which has been entered in the line edit. It will not return an empty string.</p>
113
<p>Use this static function like this:</p>
115
QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
116
tr("User name:"), QLineEdit::Normal,
117
QDir::home().dirName(), &ok);
118
if (ok && !text.isEmpty())
119
textLabel->setText(text);</pre>
120
<p>See also <a href="qinputdialog.html#getInteger">getInteger</a>(), <a href="qinputdialog.html#getDouble">getDouble</a>(), and <a href="qinputdialog.html#getItem">getItem</a>().</p>
121
<p /><address><hr /><div align="center">
122
<table width="100%" cellspacing="0" border="0"><tr class="address">
123
<td width="30%">Copyright © 2005 <a href="trolltech.html">Trolltech</a></td>
124
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
125
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
126
</tr></table></div></address></body>