2

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"
1
  • Thanks for the edit, saved me more looking Commented Aug 16, 2016 at 17:41

1 Answer 1

7

Use QInputDialog for that. The static method getText might be sufficient for you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.