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

Synopsis¶
Functions¶
def
cancelButtonText()def
comboBoxItems()def
doubleDecimals()def
doubleMaximum()def
doubleMinimum()def
doubleStep()def
doubleValue()def
inputMode()def
intMaximum()def
intMinimum()def
intStep()def
intValue()def
isComboBoxEditable()def
labelText()def
okButtonText()def
open(receiver, member)def
setCancelButtonText(text)def
setComboBoxEditable(editable)def
setComboBoxItems(items)def
setDoubleDecimals(decimals)def
setDoubleMaximum(max)def
setDoubleMinimum(min)def
setDoubleRange(min, max)def
setDoubleStep(step)def
setDoubleValue(value)def
setInputMode(mode)def
setIntMaximum(max)def
setIntMinimum(min)def
setIntRange(min, max)def
setIntStep(step)def
setIntValue(value)def
setLabelText(text)def
setOkButtonText(text)def
setOption(option[, on=true])def
setTextEchoMode(mode)def
setTextValue(text)def
testOption(option)def
textEchoMode()def
textValue()
Signals¶
def
doubleValueChanged(value)def
doubleValueSelected(value)def
intValueChanged(value)def
intValueSelected(value)def
textValueChanged(text)def
textValueSelected(text)
Static functions¶
def
getDouble(parent, title, label, value, minValue, maxValue, decimals, flags, step)def
getDouble(parent, title, label[, value=0[, minValue=-2147483647[, maxValue=2147483647[, decimals=1[, flags=Qt.WindowFlags()]]]]])def
getInt(parent, title, label[, value=0[, minValue=-2147483647[, maxValue=2147483647[, step=1[, flags=Qt.WindowFlags()]]]]])def
getItem(parent, title, label, items[, current=0[, editable=true[, flags=Qt.WindowFlags()[, inputMethodHints=Qt.ImhNone]]]])def
getMultiLineText(parent, title, label[, text=”“[, flags=Qt.WindowFlags()[, inputMethodHints=Qt.ImhNone]]])def
getText(parent, title, label[, echo=QLineEdit.Normal[, text=”“[, flags=Qt.WindowFlags()[, inputMethodHints=Qt.ImhNone]]]])
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(), andgetItem(). All the functions can be used in a similar way, for example:text = QInputDialog::getText(self, self.tr("QInputDialog().getText()"), self.tr("User name:"), QLineEdit.Normal, QDir().home().dirName(), ok) if ok and text: textLabel.setText(text)The
okvariable is set to true if the user clicks OK; otherwise, it is set to false.![]()
The Standard Dialogs example shows how to use
QInputDialogas well as other built-in Qt dialogs.See also
QMessageBoxStandard Dialogs Example
-
class
QInputDialog([parent=None[, flags=Qt.WindowFlags()]])¶ - param parent
- param flags
WindowFlags
Constructs a new input dialog with the given
parentand windowflags.
-
PySide2.QtWidgets.QInputDialog.InputDialogOption¶ This enum specifies various options that affect the look and feel of an input dialog.
Constant
Description
QInputDialog.NoButtons
Don’t display OK and Cancel buttons (useful for “live dialogs”).
QInputDialog.UseListViewForComboBoxItems
Use a
QListViewrather than a non-editableQComboBoxfor displaying the items set withsetComboBoxItems().QInputDialog.UsePlainTextEditForTextInput
Use a
QPlainTextEditfor multiline text input. This value was introduced in 5.2.See also
optionssetOption()testOption()
-
PySide2.QtWidgets.QInputDialog.InputMode¶ This enum describes the different modes of input that can be selected for the dialog.
Constant
Description
QInputDialog.TextInput
Used to input text strings.
QInputDialog.IntInput
Used to input integers.
QInputDialog.DoubleInput
Used to input floating point numbers with double precision accuracy.
See also
-
PySide2.QtWidgets.QInputDialog.cancelButtonText()¶ - Return type
unicode
See also
-
PySide2.QtWidgets.QInputDialog.comboBoxItems()¶ - Return type
list of strings
See also
-
PySide2.QtWidgets.QInputDialog.doubleDecimals()¶ - Return type
int
See also
-
PySide2.QtWidgets.QInputDialog.doubleMaximum()¶ - Return type
double
See also
-
PySide2.QtWidgets.QInputDialog.doubleMinimum()¶ - Return type
double
See also
-
PySide2.QtWidgets.QInputDialog.doubleStep()¶ - Return type
double
See also
-
PySide2.QtWidgets.QInputDialog.doubleValue()¶ - Return type
double
See also
-
PySide2.QtWidgets.QInputDialog.doubleValueChanged(value)¶ - Parameters
value –
double
-
PySide2.QtWidgets.QInputDialog.doubleValueSelected(value)¶ - Parameters
value –
double
-
static
PySide2.QtWidgets.QInputDialog.getDouble(parent, title, label, value, minValue, maxValue, decimals, flags, step)¶ - Parameters
parent –
QWidgettitle – unicode
label – unicode
value –
doubleminValue –
doublemaxValue –
doubledecimals –
intflags –
WindowFlagsstep –
double
- Return type
double
This is an overloaded function.
Static convenience function to get a floating point number from the user.
titleis the text which is displayed in the title bar of the dialog.labelis the text which is shown to the user (it should say what should be entered).valueis the default floating point number that the line edit will be set to.minandmaxare the minimum and maximum values the user may choose.decimalsis the maximum number of decimal places the number may have.stepis the amount by which the values change as the user presses the arrow buttons to increment or decrement the value.If
okis nonnull, *``ok`` will be set to true if the user pressed OK and to false if the user pressed Cancel. 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:
d = QInputDialog().getDouble(self, self.tr("QInputDialog().getDouble()"), self.tr("Amount:"), 37.56, -10000, 10000, 2, ok) if ok: doubleLabel.setText(QString("$%1").arg(d))
See also
-
static
PySide2.QtWidgets.QInputDialog.getDouble(parent, title, label[, value=0[, minValue=-2147483647[, maxValue=2147483647[, decimals=1[, flags=Qt.WindowFlags()]]]]]) - Parameters
parent –
QWidgettitle – unicode
label – unicode
value –
doubleminValue –
doublemaxValue –
doubledecimals –
intflags –
WindowFlags
- Return type
double
Static convenience function to get a floating point number from the user.
titleis the text which is displayed in the title bar of the dialog.labelis the text which is shown to the user (it should say what should be entered).valueis the default floating point number that the line edit will be set to.minandmaxare the minimum and maximum values the user may choose.decimalsis the maximum number of decimal places the number may have.If
okis nonnull, *``ok`` will be set to true if the user pressed OK and to false if the user pressed Cancel. 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:
d = QInputDialog().getDouble(self, self.tr("QInputDialog().getDouble()"), self.tr("Amount:"), 37.56, -10000, 10000, 2, ok) if ok: doubleLabel.setText(QString("$%1").arg(d))
See also
-
static
PySide2.QtWidgets.QInputDialog.getInt(parent, title, label[, value=0[, minValue=-2147483647[, maxValue=2147483647[, step=1[, flags=Qt.WindowFlags()]]]]])¶ - Parameters
parent –
QWidgettitle – unicode
label – unicode
value –
intminValue –
intmaxValue –
intstep –
intflags –
WindowFlags
- Return type
int
Static convenience function to get an integer input from the user.
titleis the text which is displayed in the title bar of the dialog.labelis the text which is shown to the user (it should say what should be entered).valueis the default integer which the spinbox will be set to.minandmaxare the minimum and maximum values the user may choose.stepis the amount by which the values change as the user presses the arrow buttons to increment or decrement the value.If
okis nonnull *``ok`` will be set to true if the user pressed OK and to false if the user pressed Cancel. 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 initial
value.Use this static function like this:
i = QInputDialog().getInteger(self, self.tr("QInputDialog().getInteger()"), self.tr("Percentage:"), 25, 0, 100, 1, ok) if ok: self.integerLabel.setText(self.tr("%1%").arg(i))
See also
-
static
PySide2.QtWidgets.QInputDialog.getItem(parent, title, label, items[, current=0[, editable=true[, flags=Qt.WindowFlags()[, inputMethodHints=Qt.ImhNone]]]])¶ - Parameters
parent –
QWidgettitle – unicode
label – unicode
items – list of strings
current –
inteditable –
boolflags –
WindowFlagsinputMethodHints –
InputMethodHints
- Return type
unicode
Static convenience function to let the user select an item from a string list.
titleis the text which is displayed in the title bar of the dialog.labelis the text which is shown to the user (it should say what should be entered).itemsis the string list which is inserted into the combo box.currentis the number of the item which should be the current item.inputMethodHintsis the input method hints that will be used if the combo box is editable and an input method is active.If
editableis true the user can enter their own text; otherwise, the user may only select one of the existing items.If
okis nonnull *ok will be set to true if the user pressed OK and to false if the user pressed Cancel. The dialog’s parent isparent. The dialog will be modal and uses the widgetflags.This function returns the text of the current item, or if
editableis true, the current text of the combo box.Use this static function like this:
items = [self.tr("Spring"), self.tr("Summer"), self.tr("Fall"), self.tr("Winter")] item = QInputDialog().getItem(self, self.tr("QInputDialog().getItem()"), selftr("Season:"), items, 0, False, ok) if ok and not item.isEmpty(): itemLabel.setText(item)
See also
-
static
PySide2.QtWidgets.QInputDialog.getMultiLineText(parent, title, label[, text=""[, flags=Qt.WindowFlags()[, inputMethodHints=Qt.ImhNone]]])¶ - Parameters
parent –
QWidgettitle – unicode
label – unicode
text – unicode
flags –
WindowFlagsinputMethodHints –
InputMethodHints
- Return type
unicode
Static convenience function to get a multiline string from the user.
titleis the text which is displayed in the title bar of the dialog.labelis the text which is shown to the user (it should say what should be entered).textis the default text which is placed in the plain text edit.inputMethodHintsis the input method hints that will be used in the edit widget if an input method is active.If
okis nonnull *ok will be set to true if the user pressed OK and to false if the user pressed Cancel. 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 plain text edit. If the dialog is rejected, a null
QStringis returned.Use this static function like this:
bool ok; QString text = QInputDialog::getMultiLineText(this, tr("QInputDialog::getMultiLineText()"), tr("Address:"), "John Doe\nFreedom Street", &ok); if (ok && !text.isEmpty()) multiLineTextLabel->setText(text);See also
-
static
PySide2.QtWidgets.QInputDialog.getText(parent, title, label[, echo=QLineEdit.Normal[, text=""[, flags=Qt.WindowFlags()[, inputMethodHints=Qt.ImhNone]]]])¶ - Parameters
parent –
QWidgettitle – unicode
label – unicode
echo –
EchoModetext – unicode
flags –
WindowFlagsinputMethodHints –
InputMethodHints
- Return type
unicode
Static convenience function to get a string from the user.
titleis the text which is displayed in the title bar of the dialog.labelis the text which is shown to the user (it should say what should be entered).textis the default text which is placed in the line edit.modeis the echo mode the line edit will use.inputMethodHintsis the input method hints that will be used in the edit widget if an input method is active.If
okis nonnull *ok will be set to true if the user pressed OK and to false if the user pressed Cancel. 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 null
QStringis returned.Use this static function like this:
text = QInputDialog::getText(self, self.tr("QInputDialog().getText()"), self.tr("User name:"), QLineEdit.Normal, QDir().home().dirName(), ok) if ok and text: textLabel.setText(text)
See also
-
PySide2.QtWidgets.QInputDialog.inputMode()¶ - Return type
See also
-
PySide2.QtWidgets.QInputDialog.intMaximum()¶ - Return type
int
See also
-
PySide2.QtWidgets.QInputDialog.intMinimum()¶ - Return type
int
See also
-
PySide2.QtWidgets.QInputDialog.intStep()¶ - Return type
int
See also
-
PySide2.QtWidgets.QInputDialog.intValue()¶ - Return type
int
See also
-
PySide2.QtWidgets.QInputDialog.intValueChanged(value)¶ - Parameters
value –
int
-
PySide2.QtWidgets.QInputDialog.intValueSelected(value)¶ - Parameters
value –
int
-
PySide2.QtWidgets.QInputDialog.isComboBoxEditable()¶ - Return type
bool
-
PySide2.QtWidgets.QInputDialog.labelText()¶ - Return type
unicode
See also
-
PySide2.QtWidgets.QInputDialog.okButtonText()¶ - Return type
unicode
See also
-
PySide2.QtWidgets.QInputDialog.open(receiver, member)¶ - Parameters
receiver –
QObjectmember – str
This function connects one of its signals to the slot specified by
receiverandmember. The specific signal depends on the arguments that are specified inmember. These are:textValueSelected()ifmemberhas aQStringfor its first argument.intValueSelected()ifmemberhas an int for its first argument.doubleValueSelected()ifmemberhas a double for its first argument.accepted()ifmemberhas NO arguments.
The signal will be disconnected from the slot when the dialog is closed.
-
PySide2.QtWidgets.QInputDialog.setCancelButtonText(text)¶ - Parameters
text – unicode
See also
-
PySide2.QtWidgets.QInputDialog.setComboBoxEditable(editable)¶ - Parameters
editable –
bool
See also
-
PySide2.QtWidgets.QInputDialog.setComboBoxItems(items)¶ - Parameters
items – list of strings
See also
-
PySide2.QtWidgets.QInputDialog.setDoubleDecimals(decimals)¶ - Parameters
decimals –
int
See also
-
PySide2.QtWidgets.QInputDialog.setDoubleMaximum(max)¶ - Parameters
max –
double
See also
-
PySide2.QtWidgets.QInputDialog.setDoubleMinimum(min)¶ - Parameters
min –
double
See also
-
PySide2.QtWidgets.QInputDialog.setDoubleRange(min, max)¶ - Parameters
min –
doublemax –
double
Sets the range of double precision floating point values accepted by the dialog when used in
DoubleInputmode, with minimum and maximum values specified byminandmaxrespectively.
-
PySide2.QtWidgets.QInputDialog.setDoubleStep(step)¶ - Parameters
step –
double
See also
-
PySide2.QtWidgets.QInputDialog.setDoubleValue(value)¶ - Parameters
value –
double
See also
-
PySide2.QtWidgets.QInputDialog.setIntMaximum(max)¶ - Parameters
max –
int
See also
-
PySide2.QtWidgets.QInputDialog.setIntMinimum(min)¶ - Parameters
min –
int
See also
-
PySide2.QtWidgets.QInputDialog.setIntRange(min, max)¶ - Parameters
min –
intmax –
int
Sets the range of integer values accepted by the dialog when used in
IntInputmode, with minimum and maximum values specified byminandmaxrespectively.
-
PySide2.QtWidgets.QInputDialog.setIntValue(value)¶ - Parameters
value –
int
See also
-
PySide2.QtWidgets.QInputDialog.setLabelText(text)¶ - Parameters
text – unicode
See also
-
PySide2.QtWidgets.QInputDialog.setOkButtonText(text)¶ - Parameters
text – unicode
See also
-
PySide2.QtWidgets.QInputDialog.setOption(option[, on=true])¶ - Parameters
option –
InputDialogOptionon –
bool
Sets the given
optionto be enabled ifonis true; otherwise, clears the givenoption.See also
optionstestOption()
-
PySide2.QtWidgets.QInputDialog.setTextEchoMode(mode)¶ - Parameters
mode –
EchoMode
See also
-
PySide2.QtWidgets.QInputDialog.setTextValue(text)¶ - Parameters
text – unicode
See also
-
PySide2.QtWidgets.QInputDialog.testOption(option)¶ - Parameters
option –
InputDialogOption- Return type
bool
Returns
trueif the givenoptionis enabled; otherwise, returns false.See also
optionssetOption()
-
PySide2.QtWidgets.QInputDialog.textEchoMode()¶ - Return type
EchoMode
See also
-
PySide2.QtWidgets.QInputDialog.textValue()¶ - Return type
unicode
See also
-
PySide2.QtWidgets.QInputDialog.textValueChanged(text)¶ - Parameters
text – unicode
-
PySide2.QtWidgets.QInputDialog.textValueSelected(text)¶ - Parameters
text – unicode
© 2018 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 the GNU 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.