|  | Home · All Classes · Modules

# QInputDialog Class Reference
[QtGui module]

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

Inherits QDialog.

### Types

- enum InputDialogOption { NoButtons, UseListViewForComboBoxItems }
- class InputDialogOptions
- enum InputMode { TextInput, IntInput, DoubleInput }

### Methods

- __init__ (self, QWidget parent = None, Qt.WindowFlags flags = 0)
- QString cancelButtonText (self)
- QStringList comboBoxItems (self)
- done (self, int result)
- int doubleDecimals (self)
- float doubleMaximum (self)
- float doubleMinimum (self)
- float doubleValue (self)
- InputMode inputMode (self)
- int intMaximum (self)
- int intMinimum (self)
- int intStep (self)
- int intValue (self)
- bool isComboBoxEditable (self)
- QString labelText (self)
- QSize minimumSizeHint (self)
- QString okButtonText (self)
- open (self)
- open (self, QObject receiver, SLOT()SLOT() member)
- open (self, callable receiver)
- InputDialogOptions options (self)
- setCancelButtonText (self, QString text)
- setComboBoxEditable (self, bool editable)
- setComboBoxItems (self, QStringList items)
- setDoubleDecimals (self, int decimals)
- setDoubleMaximum (self, float max)
- setDoubleMinimum (self, float min)
- setDoubleRange (self, float min, float max)
- setDoubleValue (self, float value)
- setInputMode (self, InputMode mode)
- setIntMaximum (self, int max)
- setIntMinimum (self, int min)
- setIntRange (self, int min, int max)
- setIntStep (self, int step)
- setIntValue (self, int value)
- setLabelText (self, QString text)
- setOkButtonText (self, QString text)
- setOption (self, InputDialogOption option, bool on = True)
- setOptions (self, InputDialogOptions options)
- setTextEchoMode (self, QLineEdit.EchoMode mode)
- setTextValue (self, QString text)
- setVisible (self, bool visible)
- QSize sizeHint (self)
- bool testOption (self, InputDialogOption option)
- QLineEdit.EchoMode textEchoMode (self)
- QString textValue (self)

### Static Methods

- (float, bool ok) getDouble (QWidget parent, QString title, QString label, float value = 0, float min = -2147483647, float max = 2147483647, int decimals = 1, Qt.WindowFlags flags = 0)
- (int, bool ok) getInt (QWidget parent, QString title, QString label, int value = 0, int min = -2147483647, int max = 2147483647, int step = 1, Qt.WindowFlags flags = 0)
- (int, bool ok) getInteger (QWidget parent, QString title, QString label, int value = 0, int min = -2147483647, int max = 2147483647, int step = 1, Qt.WindowFlags flags = 0)
- (QString, bool ok) getItem (QWidget parent, QString title, QString label, QStringList list, int current = 0, bool editable = True, Qt.WindowFlags flags = 0)
- (QString, bool ok) getText (QWidget parent, QString title, QString label, QLineEdit.EchoMode mode = QLineEdit.Normal, QString text = QString(), Qt.WindowFlags flags = 0)

### Qt Signals

- void doubleValueChanged (double)
- void doubleValueSelected (double)
- void intValueChanged (int)
- void intValueSelected (int)
- void textValueChanged (const QString&)
- void textValueSelected (const QString&)

## 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.

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

## Type Documentation

### QInputDialog.InputDialogOption

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

Constant | Value | Description
--- | --- | ---
`QInputDialog.NoButtons` | `0x00000001` | Don't display OK and Cancel buttons. (Useful for "live dialogs".)
`QInputDialog.UseListViewForComboBoxItems` | `0x00000002` | Use a QListView rather than a non-editable QComboBox for displaying the items set with setComboBoxItems().

This enum was introduced or modified 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().

### QInputDialog.InputMode

This enum describes the different modes of input that can be selected for the dialog.

Constant | Value | Description
--- | --- | ---
`QInputDialog.TextInput` | `0` | Used to input text strings.
`QInputDialog.IntInput` | `1` | Used to input integers.
`QInputDialog.DoubleInput` | `2` | Used to input floating point numbers with double precision accuracy.

This enum was introduced or modified in Qt 4.5.

See also inputMode.

## Method Documentation

### QInputDialog.__init__ (self, QWidget parent = None, Qt.WindowFlags flags = 0)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a new input dialog with the given parent and window flags.

This function was introduced in Qt 4.5.

### QString QInputDialog.cancelButtonText (self)

### QStringList QInputDialog.comboBoxItems (self)

### QInputDialog.done (self, int result)

Reimplemented from QDialog.done().

Closes the dialog and sets its result code to result. If this dialog is shown with exec_(), done() causes the local event loop to finish, and exec_() to return result.

See also QDialog.done().

### int QInputDialog.doubleDecimals (self)

### float QInputDialog.doubleMaximum (self)

### float QInputDialog.doubleMinimum (self)

### float QInputDialog.doubleValue (self)

### (float, bool ok) QInputDialog.getDouble (QWidget parent, QString title, QString label, float value = 0, float min = -2147483647, float max = 2147483647, int decimals = 1, Qt.WindowFlags flags = 0)

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

Warning: Do not delete parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QInputDialog constructors.

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

### (int, bool ok) QInputDialog.getInt (QWidget parent, QString title, QString label, int value = 0, int min = -2147483647, int max = 2147483647, int step = 1, Qt.WindowFlags flags = 0)

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. 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.getInt(this, tr("QInputDialog.getInteger()"),
                                      tr("Percentage:"), 25, 0, 100, 1, &ok);
         if (ok)
             integerLabel->setText(tr("%1%").arg(i));

Warning: Do not delete parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QInputDialog constructors.

This function was introduced in Qt 4.5.

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

### (int, bool ok) QInputDialog.getInteger (QWidget parent, QString title, QString label, int value = 0, int min = -2147483647, int max = 2147483647, int step = 1, Qt.WindowFlags flags = 0)

### (QString, bool ok) QInputDialog.getItem (QWidget parent, QString title, QString label, QStringList list, int current = 0, bool editable = True, Qt.WindowFlags flags = 0)

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. current is the number of the item which should be the current item.

If editable is true the user can enter their own text; otherwise 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);

Warning: Do not delete parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QInputDialog constructors.

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

### (QString, bool ok) QInputDialog.getText (QWidget parent, QString title, QString label, QLineEdit.EchoMode mode = QLineEdit.Normal, QString text = QString(), Qt.WindowFlags flags = 0)

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

If the dialog is accepted, this function returns the text in the dialog's line edit. If the dialog is rejected, a null QString is returned.

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);

Warning: Do not delete parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QInputDialog constructors.

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

### InputMode QInputDialog.inputMode (self)

### int QInputDialog.intMaximum (self)

### int QInputDialog.intMinimum (self)

### int QInputDialog.intStep (self)

### int QInputDialog.intValue (self)

### bool QInputDialog.isComboBoxEditable (self)

### QString QInputDialog.labelText (self)

### QSize QInputDialog.minimumSizeHint (self)

Reimplemented from QWidget.minimumSizeHint().

### QString QInputDialog.okButtonText (self)

### QInputDialog.open (self)

This is an overloaded function.

This function connects one of its signals to the slot specified by receiver and member. The specific signal depends on the arguments that are specified in member. These are:

- textValueSelected() if member has a QString for its first argument.
- intValueSelected() if member has an int for its first argument.
- doubleValueSelected() if member has a double for its first argument.
- accepted() if member has NO arguments.

The signal will be disconnected from the slot when the dialog is closed.

This function was introduced in Qt 4.5.

### QInputDialog.open (self, QObject receiver, SLOT()SLOT() member)

### QInputDialog.open (self, callable receiver)

### InputDialogOptions QInputDialog.options (self)

### QInputDialog.setCancelButtonText (self, QString text)

### QInputDialog.setComboBoxEditable (self, bool editable)

### QInputDialog.setComboBoxItems (self, QStringList items)

### QInputDialog.setDoubleDecimals (self, int decimals)

### QInputDialog.setDoubleMaximum (self, float max)

### QInputDialog.setDoubleMinimum (self, float min)

### QInputDialog.setDoubleRange (self, float min, float max)

Sets the range of double precision floating point values accepted by the dialog when used in DoubleInput mode, with minimum and maximum values specified by min and max respectively.

### QInputDialog.setDoubleValue (self, float value)

### QInputDialog.setInputMode (self, InputMode mode)

### QInputDialog.setIntMaximum (self, int max)

### QInputDialog.setIntMinimum (self, int min)

### QInputDialog.setIntRange (self, int min, int max)

Sets the range of integer values accepted by the dialog when used in IntInput mode, with minimum and maximum values specified by min and max respectively.

### QInputDialog.setIntStep (self, int step)

### QInputDialog.setIntValue (self, int value)

### QInputDialog.setLabelText (self, QString text)

### QInputDialog.setOkButtonText (self, QString text)

### QInputDialog.setOption (self, 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().

### QInputDialog.setOptions (self, InputDialogOptions options)

### QInputDialog.setTextEchoMode (self, QLineEdit.EchoMode mode)

### QInputDialog.setTextValue (self, QString text)

### QInputDialog.setVisible (self, bool visible)

Reimplemented from QWidget.setVisible().

### QSize QInputDialog.sizeHint (self)

Reimplemented from QWidget.sizeHint().

### bool QInputDialog.testOption (self, InputDialogOption option)

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

See also options and setOption().

### QLineEdit.EchoMode QInputDialog.textEchoMode (self)

### QString QInputDialog.textValue (self)

## Qt Signal Documentation

### void doubleValueChanged (double)

This is the default overload of this signal.

This signal is emitted whenever the double value changes in the dialog. The current value is specified by value.

This signal is only relevant when the input dialog is used in DoubleInput mode.

### void doubleValueSelected (double)

This is the default overload of this signal.

This signal is emitted whenever the user selects a double value by accepting the dialog; for example, by clicking the OK button. The selected value is specified by value.

This signal is only relevant when the input dialog is used in DoubleInput mode.

### void intValueChanged (int)

This is the default overload of this signal.

This signal is emitted whenever the integer value changes in the dialog. The current value is specified by value.

This signal is only relevant when the input dialog is used in IntInput mode.

### void intValueSelected (int)

This is the default overload of this signal.

This signal is emitted whenever the user selects a integer value by accepting the dialog; for example, by clicking the OK button. The selected value is specified by value.

This signal is only relevant when the input dialog is used in IntInput mode.

### void textValueChanged (const QString&)

This is the default overload of this signal.

This signal is emitted whenever the text string changes in the dialog. The current string is specified by text.

This signal is only relevant when the input dialog is used in TextInput mode.

### void textValueSelected (const QString&)

This is the default overload of this signal.

This signal is emitted whenever the user selects a text string by accepting the dialog; for example, by clicking the OK button. The selected string is specified by text.

This signal is only relevant when the input dialog is used in TextInput mode.