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> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QDialog |
List of all members, including inherited members
Public Types
| enum | InputDialogOption |
| typedef | InputDialogOptions |
| enum | InputMode |
Public Functions
| QInputDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()) | |
| ~QInputDialog() | |
| void | setInputMode(InputMode mode) |
| InputMode | inputMode() const |
| void | setLabelText(const QString &text) |
| QString | labelText() const |
| void | setOption(InputDialogOption option, bool on = true) |
| bool | testOption(InputDialogOption option) const |
| void | setOptions(InputDialogOptions options) |
| InputDialogOptions | options() const |
| void | setTextValue(const QString &text) |
| QString | textValue() const |
| void | setTextEchoMode(QLineEdit::EchoMode mode) |
| QLineEdit::EchoMode | textEchoMode() const |
| void | setComboBoxItems(const QStringList &items) |
| QStringList | comboBoxItems() const |
| void | setComboBoxEditable(bool editable) |
| bool | isComboBoxEditable() const |
| void | setIntValue(int value) |
| int | intValue() const |
| void | setIntMinimum(int min) |
| int | intMinimum() const |
| void | setIntMaximum(int max) |
| int | intMaximum() const |
| void | setIntRange(int min, int max) |
| void | setIntStep(int step) |
| int | intStep() const |
| void | setDoubleValue(double value) |
| double | doubleValue() const |
| void | setDoubleMinimum(double min) |
| double | doubleMinimum() const |
| void | setDoubleMaximum(double max) |
| double | doubleMaximum() const |
| void | setDoubleRange(double min, double max) |
| void | setDoubleDecimals(int decimals) |
| int | doubleDecimals() const |
| void | setDoubleStep(double step) |
| double | doubleStep() const |
| void | setOkButtonText(const QString &text) |
| QString | okButtonText() const |
| void | setCancelButtonText(const QString &text) |
| QString | cancelButtonText() const |
Reimplemented Public Functions
| void | done(int result) |
Signals
| void | textValueChanged(const QString &text) |
| void | textValueSelected(const QString &text) |
| void | intValueChanged(int value) |
| void | intValueSelected(int value) |
| void | doubleValueChanged(double value) |
| void | doubleValueSelected(double value) |
Static Public Members
| QString | 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()) |
| QString | getMultiLineText(QWidget *parent, const QString &title, const QString &label, const QString &text = QString(), bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()) |
| QString | 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()) |
| int | 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()) |
| double | 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) |
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>.
| Constant | Description |
|---|---|
QInputDialog::NoButtons | No OK and Cancel buttons. |
QInputDialog::UseListViewForComboBoxItems | Accepted for compatibility; the items are shown in a combo box. |
QInputDialog::UsePlainTextEditForTextInput | A 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.
| Constant | Description |
|---|---|
QInputDialog::TextInput | A text, or an item of comboBoxItems() if there are any. |
QInputDialog::IntInput | An integer. |
QInputDialog::DoubleInput | A floating-point number. |
Member Function Documentation
QInputDialog::QInputDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
Constructs an input dialog for a text with the given parent and window flags.
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().
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().
void QInputDialog::doubleValueChanged(double value)
This signal is emitted when the value changes to value in DoubleInput mode.
void QInputDialog::doubleValueSelected(double value)
This signal is emitted when the dialog is accepted in DoubleInput mode, with the value.
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.
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.
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.
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.
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().
void QInputDialog::intValueChanged(int value)
This signal is emitted when the value changes to value in IntInput mode.
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().
void QInputDialog::textValueChanged(const QString &text)
This signal is emitted when the text changes to text in TextInput mode.
void QInputDialog::textValueSelected(const QString &text)
This signal is emitted when the dialog is accepted in TextInput mode, with the text.