Home · All Namespaces · All Classes · Main Classes · Grouped Classes · Modules · Functions

QInputDialog Class Reference
[
QtGui module]

The QInputDialog class provides a simple convenience dialog to get a single value from the user. More...

 #include <QInputDialog>

Inherits QDialog.

Public Types

Properties

Public Functions

Signals

Static Public Members

Additional Inherited Members


Detailed Description

The QInputDialog class provides a simple convenience dialog to get a single value from the user.

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.

Four static convenience functions are provided: getText(), getInt(), getDouble(), and getItem(). All the functions can be used in a similar way, for example:

     bool ok;
     QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
                                          tr("User name:"), QLineEdit::Normal,
                                          QDir::home().dirName(), &ok);
     if (ok && !text.isEmpty())
         textLabel->setText(text);

The ok variable is set to true if the user clicks OK; otherwise it is set to false.

Input Dialogs

The Standard Dialogs example shows how to use QInputDialog as well as other built-in Qt dialogs.

See also QMessageBox and Standard Dialogs Example.


Member Type Documentation

enum QInputDialog::InputDialogOption
flags QInputDialog::InputDialogOptions

This enum specifies various options that affect the look and feel of an input dialog.

ConstantValueDescription
QInputDialog::NoButtons0x00000001Don't display OK and Cancel buttons. (Useful for "live dialogs".)
QInputDialog::UseListViewForComboBoxItems0x00000002Use a QListView rather than a non-editable QComboBox for displaying the items set with setComboBoxItems().

This enum was introduced in Qt 4.5.

The InputDialogOptions type is a typedef for QFlags<InputDialogOption>. It stores an OR combination of InputDialogOption values.

See also options, setOption(), and testOption().

enum QInputDialog::InputMode

###

ConstantValue
QInputDialog::TextInput0
QInputDialog::IntInput1
QInputDialog::DoubleInput2

See also inputMode.


Property Documentation

cancelButtonText : QString

###

This property was introduced in Qt 4.5.

Access functions:

comboBoxEditable : bool

Access functions:

comboBoxItems : QStringList

###

This property was introduced in Qt 4.5.

Access functions:

doubleDecimals : int

###

This property was introduced in Qt 4.5.

Access functions:

doubleMaximum : double

###

This property was introduced in Qt 4.5.

Access functions:

doubleMinimum : double

###

This property was introduced in Qt 4.5.

Access functions:

doubleValue : int

###

This property was introduced in Qt 4.5.

Access functions:

inputMode : InputMode

###

This property was introduced in Qt 4.5.

Access functions:

intMaximum : int

###

This property was introduced in Qt 4.5.

Access functions:

intMinimum : int

###

This property was introduced in Qt 4.5.

Access functions:

intStep : int

###

This property was introduced in Qt 4.5.

Access functions:

intValue : int

###

This property was introduced in Qt 4.5.

Access functions:

labelText : QString

###

This property was introduced in Qt 4.5.

Access functions:

okButtonText : QString

###

This property was introduced in Qt 4.5.

Access functions:

options : InputDialogOptions

This property holds the various options that affect the look and feel of the dialog.

By default, all options are disabled.

Access functions:

See also setOption() and testOption().

textEchoMode : QLineEdit::EchoMode

###

This property was introduced in Qt 4.5.

Access functions:

textValue : QString

###

This property was introduced in Qt 4.5.

Access functions:


Member Function Documentation

QInputDialog::QInputDialog ( QWidget * parent = 0, Qt::WindowFlags flags = 0 )

###

This function was introduced in Qt 4.5.

QInputDialog::~QInputDialog ()

Destroys the input dialog.

This function was introduced in Qt 4.5.

void QInputDialog::done ( int result )   [virtual]

void QInputDialog::doubleValueChanged ( double value )   [signal]

void QInputDialog::doubleValueSelected ( double value )   [signal]

double QInputDialog::getDouble ( QWidget * parent, const QString & title, const QString & label, double value = 0, double min = -2147483647, double max = 2147483647, int decimals = 1, bool * ok = 0, Qt::WindowFlags flags = 0 )   [static]

Static convenience function to get a floating point number from the user. title is the text which is displayed in the title bar of the dialog. label is the text which is shown to the user (it should say what should be entered). value is the default floating point number that the line edit will be set to. min and max are the minimum and maximum values the user may choose, and decimals is the maximum number of decimal places the number may have.

If ok is nonnull, *ok will be set to true if the user pressed OK and to false if the user pressed Cancel. The dialog's parent is parent. The dialog will be modal and uses the widget flags.

This function returns the floating point number which has been entered by the user.

Use this static function like this:

     bool ok;
     double d = QInputDialog::getDouble(this, tr("QInputDialog::getDouble()"),
                                        tr("Amount:"), 37.56, -10000, 10000, 2, &ok);
     if (ok)
         doubleLabel->setText(QString("$%1").arg(d));

See also getText(), getInteger(), and getItem().

int QInputDialog::getInt ( QWidget * parent, const QString & title, const QString & label, int value = 0, int min = -2147483647, int max = 2147483647, int step = 1, bool * ok = 0, Qt::WindowFlags flags = 0 )   [static]

Static convenience function to get an integer input from the user. title is the text which is displayed in the title bar of the dialog. label is the text which is shown to the user (it should say what should be entered). value is the default integer which the spinbox will be set to. min and max are the minimum and maximum values the user may choose, and step is the amount by which the values change as the user presses the arrow buttons to increment or decrement the value.

If ok is nonnull *ok will be set to true if the user pressed OK and to false if the user pressed Cancel. The dialog's parent is parent. The dialog will be modal and uses the widget flags.

On success, this function returns the integer which has been entered by the user; on failure, it returns the initial value.

Use this static function like this:

     bool ok;
     int i = QInputDialog::getInteger(this, tr("QInputDialog::getInteger()"),
                                      tr("Percentage:"), 25, 0, 100, 1, &ok);
     if (ok)
         integerLabel->setText(tr("%1%").arg(i));

See also getText(), getDouble(), and getItem().

QString QInputDialog::getItem ( QWidget * parent, const QString & title, const QString & label, const QStringList & items, int current = 0, bool editable = true, bool * ok = 0, Qt::WindowFlags flags = 0 )   [static]

Static convenience function to let the user select an item from a string list. title is the text which is displayed in the title bar of the dialog. label is the text which is shown to the user (it should say what should be entered). items is the string list which is inserted into the combobox, and current is the number of the item which should be the current item. If editable is true the user can enter their own text; if editable is false the user may only select one of the existing items.

If ok is nonnull *a ok will be set to true if the user pressed OK and to false if the user pressed Cancel. The dialog's parent is parent. The dialog will be modal and uses the widget flags.

This function returns the text of the current item, or if editable is true, the current text of the combobox.

Use this static function like this:

     QStringList items;
     items << tr("Spring") << tr("Summer") << tr("Fall") << tr("Winter");

     bool ok;
     QString item = QInputDialog::getItem(this, tr("QInputDialog::getItem()"),
                                          tr("Season:"), items, 0, false, &ok);
     if (ok && !item.isEmpty())
         itemLabel->setText(item);

See also getText(), getInteger(), and getDouble().

QString QInputDialog::getText ( QWidget * parent, const QString & title, const QString & label, QLineEdit::EchoMode mode = QLineEdit::Normal, const QString & text = QString(), bool * ok = 0, Qt::WindowFlags flags = 0 )   [static]

Static convenience function to get a string from the user. title is the text which is displayed in the title bar of the dialog. label is the text which is shown to the user (it should say what should be entered). text is the default text which is placed in the line edit. The mode is the echo mode the line edit will use. If ok is nonnull *a ok will be set to true if the user pressed OK and to false if the user pressed Cancel. The dialog's parent is parent. The dialog will be modal and uses the specified widget flags.

This function returns the text which has been entered in the line edit. It will not return an empty string.

Use this static function like this:

     bool ok;
     QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
                                          tr("User name:"), QLineEdit::Normal,
                                          QDir::home().dirName(), &ok);
     if (ok && !text.isEmpty())
         textLabel->setText(text);

See also getInteger(), getDouble(), and getItem().

void QInputDialog::intValueChanged ( int value )   [signal]

void QInputDialog::intValueSelected ( int value )   [signal]

void QInputDialog::open ()

void QInputDialog::open ( QObject * receiver, const char * member )

This is an overloaded member function, provided for convenience.

###

void QInputDialog::setDoubleRange ( double min, double max )

###

void QInputDialog::setIntRange ( int min, int max )

###

void QInputDialog::setOption ( InputDialogOption option, bool on = true )

Sets the given option to be enabled if on is true; otherwise, clears the given option.

See also options and testOption().

bool QInputDialog::testOption ( InputDialogOption option ) const

Returns true if the given option is enabled; otherwise, returns false.

See also options and setOption().

void QInputDialog::textValueChanged ( const QString & text )   [signal]

void QInputDialog::textValueSelected ( const QString & text )   [signal]


Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt 4.5.0-tp1