PySide6.QtWidgets.QInputDialog¶
- class QInputDialog¶
The
QInputDialogclass provides a simple convenience dialog to get a single value from the user. More…Synopsis¶
Methods¶
def
__init__()def
comboBoxItems()def
doubleDecimals()def
doubleMaximum()def
doubleMinimum()def
doubleStep()def
doubleValue()def
inputMode()def
intMaximum()def
intMinimum()def
intStep()def
intValue()def
labelText()def
okButtonText()def
open()def
setDoubleRange()def
setDoubleStep()def
setDoubleValue()def
setInputMode()def
setIntMaximum()def
setIntMinimum()def
setIntRange()def
setIntStep()def
setIntValue()def
setLabelText()def
setOption()def
setTextValue()def
testOption()def
textEchoMode()def
textValue()
Signals¶
Static functions¶
def
getDouble()def
getInt()def
getItem()def
getText()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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, ok = QInputDialog.getText(self, "QInputDialog.getText()", "User name:", QLineEdit.Normal, QDir.home().dirName()) 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 InputDialogOption¶
This enum specifies various options that affect the look and feel of an input dialog.
Constant
Description
QInputDialog.InputDialogOption.NoButtons
Don’t display OK and Cancel buttons (useful for “live dialogs”).
QInputDialog.InputDialogOption.UseListViewForComboBoxItems
Use a
QListViewrather than a non-editableQComboBoxfor displaying the items set withsetComboBoxItems().QInputDialog.InputDialogOption.UsePlainTextEditForTextInput
Use a
QPlainTextEditfor multiline text input. This value was introduced in 5.2.See also
optionssetOption()testOption()
- class InputMode¶
This enum describes the different modes of input that can be selected for the dialog.
Constant
Description
QInputDialog.InputMode.TextInput
Used to input text strings.
QInputDialog.InputMode.IntInput
Used to input integers.
QInputDialog.InputMode.DoubleInput
Used to input floating point numbers with double precision accuracy.
See also
- __init__([parent=None[, flags=Qt.WindowFlags()]])¶
- Parameters:
parent –
QWidgetflags – Combination of
WindowType
Constructs a new input dialog with the given
parentand windowflags.- cancelButtonText()¶
- Return type:
str
See also
- comboBoxItems()¶
- Return type:
list of strings
See also
- doubleDecimals()¶
- Return type:
int
See also
- doubleMaximum()¶
- Return type:
float
See also
- doubleMinimum()¶
- Return type:
float
See also
- doubleStep()¶
- Return type:
float
See also
- doubleValue()¶
- Return type:
float
See also
- doubleValueChanged(value)¶
- Parameters:
value – float
This signal is emitted whenever the double value changes in the dialog. The current value is specified by
value.This signal is only relevant when the input dialog is used in
DoubleInputmode.- doubleValueSelected(value)¶
- Parameters:
value – float
This signal is emitted whenever the user selects a double value by accepting the dialog; for example, by clicking the OK button. The selected value is specified by
value.This signal is only relevant when the input dialog is used in
DoubleInputmode.- static getDouble(parent, title, label[, value=0[, minValue=-2147483647[, maxValue=2147483647[, decimals=1[, flags=Qt.WindowFlags()[, step=1]]]]]])¶
- Parameters:
parent –
QWidgettitle – str
label – str
value – float
minValue – float
maxValue – float
decimals – int
flags – Combination of
WindowTypestep – float
- Return type:
float
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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, ok = QInputDialog.getDouble(self, "QInputDialog::getDouble()", "Amount:", 37.56, -10000, 10000, 2, Qt.WindowFlags(), 1) if ok: doubleLabel.setText(f"${d}")
See also
- static getInt(parent, title, label[, value=0[, minValue=-2147483647[, maxValue=2147483647[, step=1[, flags=Qt.WindowFlags()]]]]])¶
- Parameters:
parent –
QWidgettitle – str
label – str
value – int
minValue – int
maxValue – int
step – int
flags – Combination of
WindowType
- Return type:
int
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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, ok = QInputDialog.getInt(self, "QInputDialog::getInt()", "Percentage:", 25, 0, 100, 1) if ok: integerLabel.setText(f"{i}")
See also
- static getItem(parent, title, label, items[, current=0[, editable=true[, flags=Qt.WindowFlags()[, inputMethodHints=Qt.ImhNone]]]])¶
- Parameters:
parent –
QWidgettitle – str
label – str
items – list of strings
current – int
editable – bool
flags – Combination of
WindowTypeinputMethodHints – Combination of
InputMethodHint
- Return type:
str
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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 = ["Spring", "Summer", "Fall", "Winter"] item, ok = QInputDialog.getItem(self, "QInputDialog::getItem()", "Season:", items, 0, False) if ok and item: itemLabel.setText(item)
See also
- static getMultiLineText(parent, title, label[, text=""[, flags=Qt.WindowFlags()[, inputMethodHints=Qt.ImhNone]]])¶
- Parameters:
parent –
QWidgettitle – str
label – str
text – str
flags – Combination of
WindowTypeinputMethodHints – Combination of
InputMethodHint
- Return type:
str
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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 QString is returned.
Use this static function like this:
text, ok = QInputDialog.getMultiLineText(self, "QInputDialog.getMultiLineText()", "" "Address:", "John Doe\nFreedom Street") if ok and text: multiLineTextLabel.setText(text)
See also
- static getText(parent, title, label[, echo=QLineEdit.Normal[, text=""[, flags=Qt.WindowFlags()[, inputMethodHints=Qt.ImhNone]]]])¶
- Parameters:
parent –
QWidgettitle – str
label – str
echo –
EchoModetext – str
flags – Combination of
WindowTypeinputMethodHints – Combination of
InputMethodHint
- Return type:
str
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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 QString is returned.
Use this static function like this:
text, ok = QInputDialog.getText(self, "QInputDialog.getText()", "User name:", QLineEdit.Normal, QDir.home().dirName()) if ok and text: textLabel.setText(text)
See also
- inputMode()¶
- Return type:
See also
- intMaximum()¶
- Return type:
int
See also
- intMinimum()¶
- Return type:
int
See also
- intStep()¶
- Return type:
int
See also
- intValue()¶
- Return type:
int
See also
- intValueChanged(value)¶
- Parameters:
value – int
This signal is emitted whenever the integer value changes in the dialog. The current value is specified by
value.This signal is only relevant when the input dialog is used in
IntInputmode.- intValueSelected(value)¶
- Parameters:
value – int
This signal is emitted whenever the user selects a integer value by accepting the dialog; for example, by clicking the OK button. The selected value is specified by
value.This signal is only relevant when the input dialog is used in
IntInputmode.- isComboBoxEditable()¶
- Return type:
bool
- labelText()¶
- Return type:
str
See also
- okButtonText()¶
- Return type:
str
See also
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 a QString for 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.
- setCancelButtonText(text)¶
- Parameters:
text – str
See also
- setComboBoxEditable(editable)¶
- Parameters:
editable – bool
See also
- setComboBoxItems(items)¶
- Parameters:
items – list of strings
See also
- setDoubleDecimals(decimals)¶
- Parameters:
decimals – int
See also
- setDoubleMaximum(max)¶
- Parameters:
max – float
See also
- setDoubleMinimum(min)¶
- Parameters:
min – float
See also
- setDoubleRange(min, max)¶
- Parameters:
min – float
max – float
Sets the range of double precision floating point values accepted by the dialog when used in
DoubleInputmode, with minimum and maximum values specified byminandmaxrespectively.- setDoubleStep(step)¶
- Parameters:
step – float
See also
- setDoubleValue(value)¶
- Parameters:
value – float
See also
- setIntMaximum(max)¶
- Parameters:
max – int
See also
- setIntMinimum(min)¶
- Parameters:
min – int
See also
- setIntRange(min, max)¶
- Parameters:
min – int
max – int
Sets the range of integer values accepted by the dialog when used in
IntInputmode, with minimum and maximum values specified byminandmaxrespectively.- setIntValue(value)¶
- Parameters:
value – int
See also
- setLabelText(text)¶
- Parameters:
text – str
See also
- setOkButtonText(text)¶
- Parameters:
text – str
See also
- setOption(option[, on=true])¶
- Parameters:
option –
InputDialogOptionon – bool
Sets the given
optionto be enabled ifonis true; otherwise, clears the givenoption.See also
optionstestOption()- setTextValue(text)¶
- Parameters:
text – str
See also
- testOption(option)¶
- Parameters:
option –
InputDialogOption- Return type:
bool
Returns
trueif the givenoptionis enabled; otherwise, returns false.See also
optionssetOption()- textEchoMode()¶
- Return type:
See also
- textValue()¶
- Return type:
str
See also
- textValueChanged(text)¶
- Parameters:
text – str
This signal is emitted whenever the text string changes in the dialog. The current string is specified by
text.This signal is only relevant when the input dialog is used in
TextInputmode.- textValueSelected(text)¶
- Parameters:
text – str
This signal is emitted whenever the user selects a text string by accepting the dialog; for example, by clicking the OK button. The selected string is specified by
text.This signal is only relevant when the input dialog is used in
TextInputmode.