Question

I'm reading instructions for using PyQt, but I'm not getting the what-seems-like-basic-info that I need.

I need a widget. A basic one. All I want is to prompt the user to enter some text and to save said text as a string.

report_title = QInputDialog.getText(QLineEdit(), QString('Report Title:'))


TypeError: arguments did not match any overloaded call:
  QInputDialog.getText(QWidget, QString, QString, QLineEdit.EchoMode mode=QLineEdit.Normal, QString text=QString(), Qt.WindowFlags flags=0) -> (QString, bool): not enough arguments
  QInputDialog.getText(QWidget, QString, QString, QLineEdit.EchoMode, QString, Qt.WindowFlags, Qt.InputMethodHints) -> (QString, bool): not enough arguments

EDIT Placed Error in code block

Was it helpful?

Solution

The documentation for getText shows that there are at least three mandatory arguments to that static methods. They are:

  1. The parent widget (as usual)
  2. The title of the window
  3. The label, also known as, the prompt to the user. The text shown inside the dialog window, next to the input line edit.

For example:

report_title = QInputDialog.getText(someWindow, 'New report', 'Report title:')

You can pass plain python strings as QString, so there's no need to do QString('Modify report')

OTHER TIPS

You have got some examples here: http://pyqt.sourceforge.net/Docs/PyQt4/qinputdialog.html

Altough they are in C++, it is quite similar when using Python. You need to specify more arguments when calling getText() method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top