Reputation: 1295
Is there any easy and clean way to show a message box in Qt4 (PyQt4 actually) with support for text input rather than just selecting a button from a predefined list? I can (and have partially) done this by writing a custom class just for displaying such dialogs but isn't there a cleaner way?
EDIT: I got it working thanks to Luca Carlon. However just in case someone else needs this, I'll post working PyQt4 code here below
from PyQt4.QtGui import QInputDialog
#This code works only inside a method of a widget or window as self must refer to a
#valid widget or window to get the correct modality, although we can give None instead
(text,truth)=QInputDialog.getText(self,"Get text","User name",QLineEdit.Normal,"NoName")
if truth:
#The user has accepted the edit, he/she has clicked OK
print text
else:
#The user has not accepted the edit, he/she has clicked Cancel
print "No change"
Upvotes: 2
Views: 6646
Reputation: 9986
Use QInputDialog for that. The static method getText might be sufficient for you.
Upvotes: 7