6.0.0-rc4Source

QInputDialog Class

The QInputDialog class asks the user for a single value: a text, an item of a list, or a number. More…

Header#include <QInputDialog>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQDialog

List of all members, including inherited members

Public Types

Public Functions

QInputDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
~QInputDialog()
voidsetInputMode(InputMode mode)
InputModeinputMode() const
voidsetLabelText(const QString &text)
QStringlabelText() const
voidsetOption(InputDialogOption option, bool on = true)
booltestOption(InputDialogOption option) const
voidsetOptions(InputDialogOptions options)
InputDialogOptionsoptions() const
voidsetTextValue(const QString &text)
QStringtextValue() const
voidsetTextEchoMode(QLineEdit::EchoMode mode)
QLineEdit::EchoModetextEchoMode() const
voidsetComboBoxItems(const QStringList &items)
QStringListcomboBoxItems() const
voidsetComboBoxEditable(bool editable)
boolisComboBoxEditable() const
voidsetIntValue(int value)
intintValue() const
voidsetIntMinimum(int min)
intintMinimum() const
voidsetIntMaximum(int max)
intintMaximum() const
voidsetIntRange(int min, int max)
voidsetIntStep(int step)
intintStep() const
voidsetDoubleValue(double value)
doubledoubleValue() const
voidsetDoubleMinimum(double min)
doubledoubleMinimum() const
voidsetDoubleMaximum(double max)
doubledoubleMaximum() const
voidsetDoubleRange(double min, double max)
voidsetDoubleDecimals(int decimals)
intdoubleDecimals() const
voidsetDoubleStep(double step)
doubledoubleStep() const
voidsetOkButtonText(const QString &text)
QStringokButtonText() const
voidsetCancelButtonText(const QString &text)
QStringcancelButtonText() const

Reimplemented Public Functions

voiddone(int result)

Signals

voidtextValueChanged(const QString &text)
voidtextValueSelected(const QString &text)
voidintValueChanged(int value)
voidintValueSelected(int value)
voiddoubleValueChanged(double value)
voiddoubleValueSelected(double value)

Static Public Members

QStringgetText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode echo = QLineEdit::Normal, const QString &text = QString(), bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
QStringgetMultiLineText(QWidget *parent, const QString &title, const QString &label, const QString &text = QString(), bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
QStringgetItem(QWidget *parent, const QString &title, const QString &label, const QStringList &items, int current = 0, bool editable = true, bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
intgetInt(QWidget *parent, const QString &title, const QString &label, int value = 0, int minValue = -2147483647, int maxValue = 2147483647, int step = 1, bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
doublegetDouble(QWidget *parent, const QString &title, const QString &label, double value = 0, double minValue = -2147483647, double maxValue = 2147483647, int decimals = 1, bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags(), double step = 1)

Detailed Description

The static functions show the dialog and wait for the answer; ok tells whether the user accepted:

bool ok = false;
const QString name = QInputDialog::getText(window, "Rename", "New name:", QLineEdit::Normal, oldName, &ok);
if (ok && !name.isEmpty())
    rename(name);

A QInputDialog can also be set up and shown like any QDialog. The input mode says which field it shows: a line edit, a multi-line text, a combo box of items, a QSpinBox or a QDoubleSpinBox.

See also QDialog and QMessageBox.

Differences from Qt

The combo box of getItem() cannot be edited, whatever editable says, and there is no list view (UseListViewForComboBoxItems shows the combo box). The texts are not translated.

Member Type Documentation

enum QInputDialog::InputDialogOption

Options for the look of the dialog. InputDialogOptions is a typedef for QFlags<InputDialogOption>.

ConstantDescription
QInputDialog::NoButtonsNo OK and Cancel buttons.
QInputDialog::UseListViewForComboBoxItemsAccepted for compatibility; the items are shown in a combo box.
QInputDialog::UsePlainTextEditForTextInputA multi-line text instead of a line edit.

typedef QInputDialog::InputDialogOptions

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

enum QInputDialog::InputMode

Which value the dialog asks for.

ConstantDescription
QInputDialog::TextInputA text, or an item of comboBoxItems() if there are any.
QInputDialog::IntInputAn integer.
QInputDialog::DoubleInputA floating-point number.

Member Function Documentation

[explicit] QInputDialog::QInputDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())

Constructs an input dialog for a text with the given parent and window flags.

[override] QInputDialog::~QInputDialog()

Destroys the input dialog.

QString QInputDialog::cancelButtonText() const

Returns the text of the Cancel button.

See also setCancelButtonText().

QStringList QInputDialog::comboBoxItems() const

Returns the items to choose from.

See also setComboBoxItems().

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

Reimplements QDialog::done().

An accepted dialog emits textValueSelected(), intValueSelected() or doubleValueSelected() first.

int QInputDialog::doubleDecimals() const

Returns how many digits after the point the number has.

See also setDoubleDecimals().

double QInputDialog::doubleMaximum() const

Returns the largest number.

See also setDoubleMaximum().

double QInputDialog::doubleMinimum() const

Returns the smallest number.

See also setDoubleMinimum().

double QInputDialog::doubleStep() const

Returns the step of the number.

See also setDoubleStep().

double QInputDialog::doubleValue() const

Returns the value in DoubleInput mode.

See also setDoubleValue().

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

This signal is emitted when the value changes to value in DoubleInput mode.

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

This signal is emitted when the dialog is accepted in DoubleInput mode, with the value.

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

Asks for a number in a dialog with the given parent, window title, label and window flags, from minValue to maxValue with decimals digits after the point and the step, starting at value, and waits for the user. Returns the number; ok, if given, is set to whether the user accepted. A rejected dialog returns value.

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

Asks for an integer in a dialog with the given parent, window title, label and window flags, from minValue to maxValue with the step, starting at value, and waits for the user. Returns the integer; ok, if given, is set to whether the user accepted. A rejected dialog returns value.

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

Asks the user to choose one of items in a dialog with the given parent, window title, label and window flags, starting at the item current, and waits. editable is recorded but the list cannot be edited. Returns the item; ok, if given, is set to whether the user accepted. A rejected dialog returns the item at current.

[static] QString QInputDialog::getMultiLineText(QWidget *parent, const QString &title, const QString &label, const QString &text = QString(), bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())

Asks for a text of several lines in a dialog with the given parent, window title, label, window flags and starting text, and waits for the user. Returns the text; ok, if given, is set to whether the user accepted.

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

Asks for a text in a dialog with the given parent, window title, label, window flags, echo mode echo and starting text, and waits for the user. Returns the text; ok, if given, is set to whether the user accepted. A rejected dialog returns an empty string.

InputMode QInputDialog::inputMode() const

Returns which value the dialog asks for, TextInput by default.

See also setInputMode().

int QInputDialog::intMaximum() const

Returns the largest integer.

See also setIntMaximum().

int QInputDialog::intMinimum() const

Returns the smallest integer.

See also setIntMinimum().

int QInputDialog::intStep() const

Returns the step of the integer.

See also setIntStep().

int QInputDialog::intValue() const

Returns the value in IntInput mode.

See also setIntValue().

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

This signal is emitted when the value changes to value in IntInput mode.

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

This signal is emitted when the dialog is accepted in IntInput mode, with the value.

bool QInputDialog::isComboBoxEditable() const

Returns the setting of setComboBoxEditable(), true by default.

QString QInputDialog::labelText() const

Returns the text above the field.

See also setLabelText().

QString QInputDialog::okButtonText() const

Returns the text of the OK button.

See also setOkButtonText().

InputDialogOptions QInputDialog::options() const

Returns the options of the dialog.

See also setOptions().

void QInputDialog::setCancelButtonText(const QString &text)

Sets the text of the Cancel button to text.

See also cancelButtonText().

void QInputDialog::setComboBoxEditable(bool editable)

Sets whether the user may type a text that is not an item to editable. The combo box of Nt cannot be edited, so it only records the setting.

See also isComboBoxEditable().

void QInputDialog::setComboBoxItems(const QStringList &items)

Sets the items to choose from in TextInput mode to items. With items the dialog shows a combo box instead of a line edit.

See also comboBoxItems().

void QInputDialog::setDoubleDecimals(int decimals)

Sets how many digits after the point the number has to decimals.

See also doubleDecimals().

void QInputDialog::setDoubleMaximum(double max)

Sets the largest number to max.

See also doubleMaximum() and setDoubleRange().

void QInputDialog::setDoubleMinimum(double min)

Sets the smallest number to min.

See also doubleMinimum() and setDoubleRange().

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

Sets the range of the number to min to max.

void QInputDialog::setDoubleStep(double step)

Sets the step of the number to step.

See also doubleStep().

void QInputDialog::setDoubleValue(double value)

Sets the value in DoubleInput mode to value.

See also doubleValue().

void QInputDialog::setInputMode(InputMode mode)

Sets which value the dialog asks for to mode.

See also inputMode().

void QInputDialog::setIntMaximum(int max)

Sets the largest integer to max.

See also intMaximum() and setIntRange().

void QInputDialog::setIntMinimum(int min)

Sets the smallest integer to min.

See also intMinimum() and setIntRange().

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

Sets the range of the integer to min to max.

void QInputDialog::setIntStep(int step)

Sets the step of the integer to step.

See also intStep().

void QInputDialog::setIntValue(int value)

Sets the value in IntInput mode to value.

See also intValue().

void QInputDialog::setLabelText(const QString &text)

Sets the text above the field to text.

See also labelText().

void QInputDialog::setOkButtonText(const QString &text)

Sets the text of the OK button to text.

See also okButtonText().

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

Sets option if on is true, and clears it otherwise.

See also testOption() and setOptions().

void QInputDialog::setOptions(InputDialogOptions options)

Sets the options of the dialog to options.

See also options().

void QInputDialog::setTextEchoMode(QLineEdit::EchoMode mode)

Sets how the line edit shows the text to mode, such as QLineEdit::Password.

See also textEchoMode().

void QInputDialog::setTextValue(const QString &text)

Sets the text of the field in TextInput mode to text, and selects the item with that text if there are items.

See also textValue().

bool QInputDialog::testOption(InputDialogOption option) const

Returns whether option is set.

See also setOption().

QLineEdit::EchoMode QInputDialog::textEchoMode() const

Returns how the line edit shows the text.

See also setTextEchoMode().

QString QInputDialog::textValue() const

Returns the text of the field in TextInput mode: the text of the line edit or the multi-line text, or the current item.

See also setTextValue().

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

This signal is emitted when the text changes to text in TextInput mode.

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

This signal is emitted when the dialog is accepted in TextInput mode, with the text.