QInputDialog

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

Inheritance diagram of PySide6.QtWidgets.QInputDialog

Synopsis

Functions

Signals

Static functions

  • def getDouble (parent, title, label[, value=0[, minValue=-2147483647[, maxValue=2147483647[, decimals=1[, flags=Qt.WindowFlags()[, step=1]]]]]])

  • 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() , and getItem() . All the functions can be used in a similar way, for example:

ok = bool()
text = QInputDialog.getText(self, tr("QInputDialog.getText()"),()
                                     tr("User name:"), QLineEdit.Normal,
                                     QDir.home().dirName(), ok)
if (ok and not text.isEmpty())
    textLabel.setText(text)

The ok variable is set to true if the user clicks OK; otherwise, it is set to false.

../../_images/inputdialogs.png

The Standard Dialogs example shows how to use QInputDialog as well as other built-in Qt dialogs.

class PySide6.QtWidgets.QInputDialog([parent=None[, flags=Qt.WindowFlags()]])
Parameters

Constructs a new input dialog with the given parent and window flags.

PySide6.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 QListView rather than a non-editable QComboBox for displaying the items set with setComboBoxItems() .

QInputDialog.UsePlainTextEditForTextInput

Use a QPlainTextEdit for multiline text input. This value was introduced in 5.2.

See also

options setOption() testOption()

PySide6.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

inputMode

PySide6.QtWidgets.QInputDialog.cancelButtonText()
Return type

str

PySide6.QtWidgets.QInputDialog.comboBoxItems()
Return type

list of strings

PySide6.QtWidgets.QInputDialog.doubleDecimals()
Return type

int

PySide6.QtWidgets.QInputDialog.doubleMaximum()
Return type

double

PySide6.QtWidgets.QInputDialog.doubleMinimum()
Return type

double

PySide6.QtWidgets.QInputDialog.doubleStep()
Return type

double

See also

setDoubleStep()

PySide6.QtWidgets.QInputDialog.doubleValue()
Return type

double

See also

setDoubleValue()

PySide6.QtWidgets.QInputDialog.doubleValueChanged(value)
Parameters

valuedouble

PySide6.QtWidgets.QInputDialog.doubleValueSelected(value)
Parameters

valuedouble

static PySide6.QtWidgets.QInputDialog.getDouble(parent, title, label[, value=0[, minValue=-2147483647[, maxValue=2147483647[, decimals=1[, flags=Qt.WindowFlags()[, step=1]]]]]])
Parameters
  • parentPySide6.QtWidgets.QWidget

  • title – str

  • label – str

  • valuedouble

  • minValuedouble

  • maxValuedouble

  • decimals – int

  • flagsWindowFlags

  • stepdouble

Return type

double

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 and max are the minimum and maximum values the user may choose. decimals is the maximum number of decimal places the number may have. step is the amount by which the values change as the user presses the arrow buttons to increment or decrement the value.

If ok is nonnull, *``ok`` will be set to true if the user pressed OK and to false if the user pressed Cancel. The dialog’s parent is parent. The dialog will be modal and uses the widget flags.

This function returns the floating point number which has been entered by the user.

Use this static function like this:

ok = bool()
d = QInputDialog.getDouble(self, tr("QInputDialog.getDouble()"),()
                                   tr("Amount:"), 37.56, -10000, 10000, 2, ok,
                                   Qt.WindowFlags(), 1)
if (ok)
    doubleLabel.setText(QString("$%1").arg(d))
static PySide6.QtWidgets.QInputDialog.getInt(parent, title, label[, value=0[, minValue=-2147483647[, maxValue=2147483647[, step=1[, flags=Qt.WindowFlags()]]]]])
Parameters
  • parentPySide6.QtWidgets.QWidget

  • title – str

  • label – str

  • value – int

  • minValue – int

  • maxValue – int

  • step – int

  • flagsWindowFlags

Return type

int

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 and max 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.

If ok is nonnull *``ok`` will be set to true if the user pressed OK and to false if the user pressed Cancel. The dialog’s parent is parent. The dialog will be modal and uses the widget flags.

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:

ok = bool()
i = QInputDialog.getInt(self, tr("QInputDialog.getInt()"),()
                             tr("Percentage:"), 25, 0, 100, 1, ok)
if (ok)
    integerLabel.setText(tr("%1%").arg(i))
static PySide6.QtWidgets.QInputDialog.getItem(parent, title, label, items[, current=0[, editable=true[, flags=Qt.WindowFlags()[, inputMethodHints=Qt.ImhNone]]]])
Parameters
  • parentPySide6.QtWidgets.QWidget

  • title – str

  • label – str

  • items – list of strings

  • current – int

  • editable – bool

  • flagsWindowFlags

  • inputMethodHintsInputMethodHints

Return type

str

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 combo box. 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 combo box is editable and an input method is active.

If editable is true the user can enter their own text; otherwise, the user may only select one of the existing items.

If ok is nonnull *ok will be set to true if the user pressed OK and to false if the user pressed Cancel. The dialog’s parent is parent. The dialog will be modal and uses the widget flags.

This function returns the text of the current item, or if editable is true, the current text of the combo box.

Use this static function like this:

items = QStringList()
items << tr("Spring") << tr("Summer") << tr("Fall") << tr("Winter")
ok = bool()
item = QInputDialog.getItem(self, tr("QInputDialog.getItem()"),()
                                     tr("Season:"), items, 0, False, ok)
if (ok and not item.isEmpty())
    itemLabel.setText(item)
static PySide6.QtWidgets.QInputDialog.getMultiLineText(parent, title, label[, text=""[, flags=Qt.WindowFlags()[, inputMethodHints=Qt.ImhNone]]])
Parameters
  • parentPySide6.QtWidgets.QWidget

  • title – str

  • label – str

  • text – str

  • flagsWindowFlags

  • inputMethodHintsInputMethodHints

Return type

str

Static convenience function to get a multiline 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 plain text edit. inputMethodHints is the input method hints that will be used in the edit widget if an input method is active.

If ok is nonnull *ok will be set to true if the user pressed OK and to false if the user pressed Cancel. The dialog’s parent is parent. The dialog will be modal and uses the specified widget flags.

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:

ok = bool()
text = QInputDialog.getMultiLineText(self, tr("QInputDialog.getMultiLineText()"),()
                                              tr("Address:"), "John Doe\nFreedom Street", ok)
if (ok and not text.isEmpty())
    multiLineTextLabel.setText(text)
static PySide6.QtWidgets.QInputDialog.getText(parent, title, label[, echo=QLineEdit.Normal[, text=""[, flags=Qt.WindowFlags()[, inputMethodHints=Qt.ImhNone]]]])
Parameters
Return type

str

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.

If ok is nonnull *ok will be set to true if the user pressed OK and to false if the user pressed Cancel. The dialog’s parent is parent. The dialog will be modal and uses the specified widget flags.

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:

ok = bool()
text = QInputDialog.getText(self, tr("QInputDialog.getText()"),()
                                     tr("User name:"), QLineEdit.Normal,
                                     QDir.home().dirName(), ok)
if (ok and not text.isEmpty())
    textLabel.setText(text)
PySide6.QtWidgets.QInputDialog.inputMode()
Return type

InputMode

See also

setInputMode()

PySide6.QtWidgets.QInputDialog.intMaximum()
Return type

int

See also

setIntMaximum()

PySide6.QtWidgets.QInputDialog.intMinimum()
Return type

int

See also

setIntMinimum()

PySide6.QtWidgets.QInputDialog.intStep()
Return type

int

See also

setIntStep()

PySide6.QtWidgets.QInputDialog.intValue()
Return type

int

See also

setIntValue()

PySide6.QtWidgets.QInputDialog.intValueChanged(value)
Parameters

value – int

PySide6.QtWidgets.QInputDialog.intValueSelected(value)
Parameters

value – int

PySide6.QtWidgets.QInputDialog.isComboBoxEditable()
Return type

bool

PySide6.QtWidgets.QInputDialog.labelText()
Return type

str

See also

setLabelText()

PySide6.QtWidgets.QInputDialog.okButtonText()
Return type

str

PySide6.QtWidgets.QInputDialog.open(receiver, member)
Parameters

This function connects one of its signals to the slot specified by receiver and member. The specific signal depends on the arguments that are specified in member. These are:

The signal will be disconnected from the slot when the dialog is closed.

PySide6.QtWidgets.QInputDialog.setCancelButtonText(text)
Parameters

text – str

PySide6.QtWidgets.QInputDialog.setComboBoxEditable(editable)
Parameters

editable – bool

PySide6.QtWidgets.QInputDialog.setComboBoxItems(items)
Parameters

items – list of strings

See also

comboBoxItems()

PySide6.QtWidgets.QInputDialog.setDoubleDecimals(decimals)
Parameters

decimals – int

See also

doubleDecimals()

PySide6.QtWidgets.QInputDialog.setDoubleMaximum(max)
Parameters

maxdouble

See also

doubleMaximum()

PySide6.QtWidgets.QInputDialog.setDoubleMinimum(min)
Parameters

mindouble

See also

doubleMinimum()

PySide6.QtWidgets.QInputDialog.setDoubleRange(min, max)
Parameters
  • mindouble

  • maxdouble

Sets the range of double precision floating point values accepted by the dialog when used in DoubleInput mode, with minimum and maximum values specified by min and max respectively.

PySide6.QtWidgets.QInputDialog.setDoubleStep(step)
Parameters

stepdouble

See also

doubleStep()

PySide6.QtWidgets.QInputDialog.setDoubleValue(value)
Parameters

valuedouble

See also

doubleValue()

PySide6.QtWidgets.QInputDialog.setInputMode(mode)
Parameters

modeInputMode

See also

inputMode()

PySide6.QtWidgets.QInputDialog.setIntMaximum(max)
Parameters

max – int

See also

intMaximum()

PySide6.QtWidgets.QInputDialog.setIntMinimum(min)
Parameters

min – int

See also

intMinimum()

PySide6.QtWidgets.QInputDialog.setIntRange(min, max)
Parameters
  • min – int

  • max – int

Sets the range of integer values accepted by the dialog when used in IntInput mode, with minimum and maximum values specified by min and max respectively.

PySide6.QtWidgets.QInputDialog.setIntStep(step)
Parameters

step – int

See also

intStep()

PySide6.QtWidgets.QInputDialog.setIntValue(value)
Parameters

value – int

See also

intValue()

PySide6.QtWidgets.QInputDialog.setLabelText(text)
Parameters

text – str

See also

labelText()

PySide6.QtWidgets.QInputDialog.setOkButtonText(text)
Parameters

text – str

See also

okButtonText()

PySide6.QtWidgets.QInputDialog.setOption(option[, on=true])
Parameters

Sets the given option to be enabled if on is true; otherwise, clears the given option.

See also

options testOption()

PySide6.QtWidgets.QInputDialog.setTextEchoMode(mode)
Parameters

modeEchoMode

See also

textEchoMode()

PySide6.QtWidgets.QInputDialog.setTextValue(text)
Parameters

text – str

See also

textValue()

PySide6.QtWidgets.QInputDialog.testOption(option)
Parameters

optionInputDialogOption

Return type

bool

Returns true if the given option is enabled; otherwise, returns false.

See also

options setOption()

PySide6.QtWidgets.QInputDialog.textEchoMode()
Return type

EchoMode

PySide6.QtWidgets.QInputDialog.textValue()
Return type

str

See also

setTextValue()

PySide6.QtWidgets.QInputDialog.textValueChanged(text)
Parameters

text – str

PySide6.QtWidgets.QInputDialog.textValueSelected(text)
Parameters

text – str