
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQInputDialog class provides a simple convenience dialog to get a single value from the user.More...
| Header: | #include <QInputDialog> |
| Inherits: | QDialog |
| enum | InputDialogOption { NoButtons, UseListViewForComboBoxItems } |
| flags | InputDialogOptions |
| enum | InputMode { TextInput, IntInput, DoubleInput } |
|
|
| QInputDialog(QWidget * parent = 0, Qt::WindowFlags flags = 0) | |
| ~QInputDialog() | |
| QString | cancelButtonText() const |
| QStringList | comboBoxItems() const |
| int | doubleDecimals() const |
| double | doubleMaximum() const |
| double | doubleMinimum() const |
| double | doubleValue() const |
| InputMode | inputMode() const |
| int | intMaximum() const |
| int | intMinimum() const |
| int | intStep() const |
| int | intValue() const |
| bool | isComboBoxEditable() const |
| QString | labelText() const |
| QString | okButtonText() const |
| void | open(QObject * receiver, const char * member) |
| 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 | setDoubleRange(double min, double max) |
| void | setDoubleValue(double value) |
| void | setInputMode(InputMode mode) |
| void | setIntMaximum(int max) |
| void | setIntMinimum(int min) |
| void | setIntRange(int min, int max) |
| void | setIntStep(int step) |
| void | setIntValue(int value) |
| void | setLabelText(const QString & text) |
| void | setOkButtonText(const QString & text) |
| void | setOption(InputDialogOption option, bool on = true) |
| void | setOptions(InputDialogOptions options) |
| void | setTextEchoMode(QLineEdit::EchoMode mode) |
| void | setTextValue(const QString & text) |
| bool | testOption(InputDialogOption option) const |
| QLineEdit::EchoMode | textEchoMode() const |
| QString | textValue() const |
| virtual void | done(int result) |
| virtual QSize | minimumSizeHint() const |
| virtual void | setVisible(bool visible) |
| virtual QSize | sizeHint() const |
| void | doubleValueChanged(double value) |
| void | doubleValueSelected(double value) |
| void | intValueChanged(int value) |
| void | intValueSelected(int value) |
| void | textValueChanged(const QString & text) |
| void | textValueSelected(const QString & text) |
| double | 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) |
| int | 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) |
| QString | 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, Qt::InputMethodHints inputMethodHints = Qt::ImhNone) |
| QString | 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, Qt::InputMethodHints inputMethodHints = Qt::ImhNone) |
TheQInputDialog 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(), andgetItem(). 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);
Theok variable is set to true if the user clicksOK; otherwise it is set to false.

TheStandard Dialogs example shows how to useQInputDialog as well as other built-in Qt dialogs.
See alsoQMessageBox andStandard Dialogs Example.
This enum specifies various options that affect the look and feel of an input dialog.
| Constant | Value | Description |
|---|---|---|
QInputDialog::NoButtons | 0x00000001 | Don't displayOK andCancel buttons. (Useful for "live dialogs".) |
QInputDialog::UseListViewForComboBoxItems | 0x00000002 | Use aQListView rather than a non-editableQComboBox for displaying the items set withsetComboBoxItems(). |
This enum was introduced or modified in Qt 4.5.
The InputDialogOptions type is a typedef forQFlags<InputDialogOption>. It stores an OR combination of InputDialogOption values.
See alsooptions,setOption(), andtestOption().
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 alsoinputMode.
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) |
This property holds whether or not the combo box is used in the input dialog is editable.
This property was introduced in Qt 4.5.
Access functions:
| bool | isComboBoxEditable() const |
| void | setComboBoxEditable(bool editable) |
This property holds the items used in the combobox for the input dialog.
This property was introduced in Qt 4.5.
Access functions:
| QStringList | comboBoxItems() const |
| void | setComboBoxItems(const QStringList & items) |
This property holds sets the percision of the double spinbox in decimals.
This property was introduced in Qt 4.5.
Access functions:
| int | doubleDecimals() const |
| void | setDoubleDecimals(int decimals) |
See alsoQDoubleSpinBox::setDecimals().
This property holds the maximum double precision floating point value accepted as input.
This property is only relevant when the input dialog is used inDoubleInput mode.
This property was introduced in Qt 4.5.
Access functions:
| double | doubleMaximum() const |
| void | setDoubleMaximum(double max) |
This property holds the minimum double precision floating point value accepted as input.
This property is only relevant when the input dialog is used inDoubleInput mode.
This property was introduced in Qt 4.5.
Access functions:
| double | doubleMinimum() const |
| void | setDoubleMinimum(double min) |
This property holds the current double precision floating point value accepted as input.
This property is only relevant when the input dialog is used inDoubleInput mode.
This property was introduced in Qt 4.5.
Access functions:
| double | doubleValue() const |
| void | setDoubleValue(double value) |
Notifier signal:
| void | doubleValueChanged(double value) |
This property holds the mode used for input.
This property help determines which widget is used for entering input into the dialog.
This property was introduced in Qt 4.5.
Access functions:
| InputMode | inputMode() const |
| void | setInputMode(InputMode mode) |
This property holds the maximum integer value accepted as input.
This property is only relevant when the input dialog is used inIntInput mode.
This property was introduced in Qt 4.5.
Access functions:
| int | intMaximum() const |
| void | setIntMaximum(int max) |
This property holds the minimum integer value accepted as input.
This property is only relevant when the input dialog is used inIntInput mode.
This property was introduced in Qt 4.5.
Access functions:
| int | intMinimum() const |
| void | setIntMinimum(int min) |
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 inIntInput mode.
This property was introduced in Qt 4.5.
Access functions:
| int | intStep() const |
| void | setIntStep(int step) |
This property holds the current integer value accepted as input.
This property is only relevant when the input dialog is used inIntInput mode.
This property was introduced in Qt 4.5.
Access functions:
| int | intValue() const |
| void | setIntValue(int value) |
Notifier signal:
| void | intValueChanged(int value) |
This property holds the text to for the label to describe what needs to be input.
This property was introduced in Qt 4.5.
Access functions:
| QString | labelText() const |
| void | setLabelText(const QString & text) |
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) |
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:
| InputDialogOptions | options() const |
| void | setOptions(InputDialogOptions options) |
See alsosetOption() andtestOption().
This property holds the echo mode for the text value.
This property is only relevant when the input dialog is used inTextInput mode.
This property was introduced in Qt 4.5.
Access functions:
| QLineEdit::EchoMode | textEchoMode() const |
| void | setTextEchoMode(QLineEdit::EchoMode mode) |
This property holds the text value for the input dialog.
This property is only relevant when the input dialog is used inTextInput 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) |
Constructs a new input dialog with the givenparent and windowflags.
This function was introduced in Qt 4.5.
Destroys the input dialog.
This function was introduced in Qt 4.5.
[virtual]void QInputDialog::done(int result)Reimplemented fromQDialog::done().
Closes the dialog and sets its result code toresult. If this dialog is shown withexec(), done() causes the local event loop to finish, andexec() to returnresult.
See alsoQDialog::done().
[signal]void QInputDialog::doubleValueSelected(double value)This signal is emitted whenever the user selects a double value by accepting the dialog; for example, by clicking theOK button. The selected value is specified byvalue.
This signal is only relevant when the input dialog is used inDoubleInput mode.
[static]double QInputDialog::getDouble(QWidget * parent, constQString & title, constQString & label,double value = 0,double min = -2147483647,double max = 2147483647,int decimals = 1,bool * ok = 0,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 andmax are the minimum and maximum values the user may choose.decimals is the maximum number of decimal places the number may have.
Ifok is nonnull, *ok will be set to true if the user pressedOK and to false if the user pressedCancel. The dialog's parent isparent. The dialog will be modal and uses the widgetflags.
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 deleteparent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of theQInputDialog constructors.
See alsogetText(),getInt(), andgetItem().
[static]int QInputDialog::getInt(QWidget * parent, constQString & title, constQString & label,int value = 0,int min = -2147483647,int max = 2147483647,int step = 1,bool * ok = 0,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 andmax 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.
Ifok is nonnull *ok will be set to true if the user pressedOK and to false if the user pressedCancel. The dialog's parent isparent. The dialog will be modal and uses the widgetflags.
On success, this function returns the integer which has been entered by the user; on failure, it returns the initialvalue.
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 deleteparent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of theQInputDialog constructors.
This function was introduced in Qt 4.5.
See alsogetText(),getDouble(), andgetItem().
[static]QString QInputDialog::getItem(QWidget * parent, constQString & title, constQString & label, constQStringList & items,int current = 0,bool editable = true,bool * ok = 0,Qt::WindowFlags flags = 0,Qt::InputMethodHints inputMethodHints = Qt::ImhNone)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.inputMethodHints is the input method hints that will be used if the combobox is editable and an input method is active.
Ifeditable is true the user can enter their own text; otherwise the user may only select one of the existing items.
Ifok is nonnull*a ok will be set to true if the user pressedOK and to false if the user pressedCancel. The dialog's parent isparent. The dialog will be modal and uses the widgetflags.
This function returns the text of the current item, or ifeditable 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 deleteparent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of theQInputDialog constructors.
See alsogetText(),getInt(), andgetDouble().
[static]QString QInputDialog::getText(QWidget * parent, constQString & title, constQString & label,QLineEdit::EchoMode mode = QLineEdit::Normal, constQString & text = QString(),bool * ok = 0,Qt::WindowFlags flags = 0,Qt::InputMethodHints inputMethodHints = Qt::ImhNone)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.inputMethodHints is the input method hints that will be used in the edit widget if an input method is active.
Ifok is nonnull*a ok will be set to true if the user pressedOK and to false if the user pressedCancel. The dialog's parent isparent. The dialog will be modal and uses the specified widgetflags.
If the dialog is accepted, this function returns the text in the dialog's line edit. If the dialog is rejected, a nullQString 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 deleteparent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of theQInputDialog constructors.
See alsogetInt(),getDouble(), andgetItem().
[signal]void QInputDialog::intValueSelected(int value)This signal is emitted whenever the user selects a integer value by accepting the dialog; for example, by clicking theOK button. The selected value is specified byvalue.
This signal is only relevant when the input dialog is used inIntInput mode.
[virtual]QSize QInputDialog::minimumSizeHint() constReimplemented fromQWidget::minimumSizeHint().
This is an overloaded function.
This function connects one of its signals to the slot specified byreceiver andmember. The specific signal depends on the arguments that are specified inmember. These are:
The signal will be disconnected from the slot when the dialog is closed.
This function was introduced in Qt 4.5.
Sets the range of double precision floating point values accepted by the dialog when used inDoubleInput mode, with minimum and maximum values specified bymin andmax respectively.
Sets the range of integer values accepted by the dialog when used inIntInput mode, with minimum and maximum values specified bymin andmax respectively.
Sets the givenoption to be enabled ifon is true; otherwise, clears the givenoption.
See alsooptions andtestOption().
[virtual]void QInputDialog::setVisible(bool visible)Reimplemented fromQWidget::setVisible().
[virtual]QSize QInputDialog::sizeHint() constReimplemented fromQWidget::sizeHint().
Returns true if the givenoption is enabled; otherwise, returns false.
See alsooptions andsetOption().
[signal]void QInputDialog::textValueSelected(constQString & text)This signal is emitted whenever the user selects a text string by accepting the dialog; for example, by clicking theOK button. The selected string is specified bytext.
This signal is only relevant when the input dialog is used inTextInput mode.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.