QInputDialog Class

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

Header: #include <QInputDialog>
qmake: QT += widgets
Inherits: QDialog

Public Types

enum InputDialogOption { NoButtons, UseListViewForComboBoxItems, UsePlainTextEditForTextInput }
enum InputMode { TextInput, IntInput, DoubleInput }

Properties

Public Functions

QString cancelButtonText() const
QStringList comboBoxItems() const
int doubleDecimals() const
double doubleMaximum() const
double doubleMinimum() const
double doubleStep() const
double doubleValue() const
QInputDialog::InputMode inputMode() const
int intMaximum() const
int intMinimum() const
int intStep() const
int intValue() const
bool isComboBoxEditable() const
QString labelText() const
QString okButtonText() const
QInputDialog::InputDialogOptions options() const
void setCancelButtonText(const QString &text)
void setComboBoxEditable(bool editable)
void setComboBoxItems(const QStringList &items)
void setDoubleDecimals(int decimals)
void setDoubleMaximum(double max)
void setDoubleMinimum(double min)
void setDoubleStep(double step)
void setDoubleValue(double value)
void setInputMode(QInputDialog::InputMode mode)
void setIntMaximum(int max)
void setIntMinimum(int min)
void setIntStep(int step)
void setIntValue(int value)
void setLabelText(const QString &text)
void setOkButtonText(const QString &text)
void setOptions(QInputDialog::InputDialogOptions options)
void setTextEchoMode(QLineEdit::EchoMode mode)
void setTextValue(const QString &text)
QLineEdit::EchoMode textEchoMode() const
QString textValue() const

Signals

void doubleValueChanged(double value)
void intValueChanged(int value)
void textValueChanged(const QString &text)

Detailed Description

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.

Five static convenience functions are provided: getText(), getMultiLineText(), 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

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().
QInputDialog::UsePlainTextEditForTextInput0x00000004Use a QPlainTextEdit for multiline text input. This value was introduced in 5.2.

This enum was introduced or modified in Qt 4.5.

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

enum QInputDialog::InputMode

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

ConstantValueDescription
QInputDialog::TextInput0Used to input text strings.
QInputDialog::IntInput1Used to input integers.
QInputDialog::DoubleInput2Used to input floating point numbers with double precision accuracy.

This enum was introduced or modified in Qt 4.5.

See also inputMode.

Property Documentation

cancelButtonText : QString

This property holds the text for the button used to cancel the dialog

This property was introduced in Qt 4.5.

Access functions:

QString cancelButtonText() const
void setCancelButtonText(const QString &text)

comboBoxEditable : bool

This property holds whether or not the combo box used in the input dialog is editable

This property was introduced in Qt 4.5.

Access functions:

bool isComboBoxEditable() const
void setComboBoxEditable(bool editable)

comboBoxItems : QStringList

This property holds the items used in the combo box for the input dialog

This property was introduced in Qt 4.5.

Access functions:

QStringList comboBoxItems() const
void setComboBoxItems(const QStringList &items)

doubleDecimals : int

sets the precision of the double spinbox in decimals

This property was introduced in Qt 4.5.

Access functions:

int doubleDecimals() const
void setDoubleDecimals(int decimals)

See also QDoubleSpinBox::setDecimals().

doubleMaximum : double

This property holds the maximum double precision floating point value accepted as input

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

This property was introduced in Qt 4.5.

Access functions:

double doubleMaximum() const
void setDoubleMaximum(double max)

doubleMinimum : double

This property holds the minimum double precision floating point value accepted as input

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

This property was introduced in Qt 4.5.

Access functions:

double doubleMinimum() const
void setDoubleMinimum(double min)

doubleStep : double

This property holds the step by which the double value is increased and decreased

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

This property was introduced in Qt 5.10.

Access functions:

double doubleStep() const
void setDoubleStep(double step)

doubleValue : int

This property holds the current double precision floating point value accepted as input

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

This property was introduced in Qt 4.5.

Access functions:

double doubleValue() const
void setDoubleValue(double value)

Notifier signal:

void doubleValueChanged(double value)

inputMode : InputMode

This property holds the mode used for input

This property helps determine which widget is used for entering input into the dialog.

This property was introduced in Qt 4.5.

Access functions:

QInputDialog::InputMode inputMode() const
void setInputMode(QInputDialog::InputMode mode)

intMaximum : int

This property holds the maximum integer value accepted as input

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

This property was introduced in Qt 4.5.

Access functions:

int intMaximum() const
void setIntMaximum(int max)

intMinimum : int

This property holds the minimum integer value accepted as input

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

This property was introduced in Qt 4.5.

Access functions:

int intMinimum() const
void setIntMinimum(int min)

intStep : int

This property holds the step by which the integer value is increased and decreased

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

This property was introduced in Qt 4.5.

Access functions:

int intStep() const
void setIntStep(int step)

intValue : int

This property holds the current integer value accepted as input

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

This property was introduced in Qt 4.5.

Access functions:

int intValue() const
void setIntValue(int value)

Notifier signal:

void intValueChanged(int value)

labelText : QString

This property holds the label's text which describes what needs to be input

This property was introduced in Qt 4.5.

Access functions:

QString labelText() const
void setLabelText(const QString &text)

okButtonText : QString

This property holds the text for the button used to accept the entry in the dialog

This property was introduced in Qt 4.5.

Access functions:

QString okButtonText() const
void setOkButtonText(const QString &text)

options : InputDialogOptions

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

By default, all options are disabled.

This property was introduced in Qt 4.5.

Access functions:

QInputDialog::InputDialogOptions options() const
void setOptions(QInputDialog::InputDialogOptions options)

See also setOption() and testOption().

textEchoMode : QLineEdit::EchoMode

This property holds the echo mode for the text value

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

This property was introduced in Qt 4.5.

Access functions:

QLineEdit::EchoMode textEchoMode() const
void setTextEchoMode(QLineEdit::EchoMode mode)

textValue : QString

This property holds the text value for the input dialog

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

This property was introduced in Qt 4.5.

Access functions:

QString textValue() const
void setTextValue(const QString &text)

Notifier signal:

void textValueChanged(const QString &text)