Search code examples
pythonqtqtextedit

Qt Python: QTextEdit - display input


I have a QTextEdit... it works with 'clear()' when a pushbutton calls 'CleanComments' to clean the input done by the user. Here is the code:

def CleanComments(self):
    self.textEditInput.clear()

def showInput(self):
    print "show input: %s" % self.textEditInput.show()

def buildEditInput(self):
    self.textEditInput = QtGui.QTextEdit(self.boxForm)
    self.textEditInput.setGeometry(QtCore.QRect(10, 300, 500, 100)) 

The only problem is, that when 'showInput' is called to display the content on QTextEdit using "show()", it gives "" show input: 'None' "". So, what is missing here?

All comments and suggestions are highly appreciated.


Solution

  • To get the contents of a QTextEdit as a simple string, use the toPlainText() method.

    print "show input: %s" % self.textEditInput.toPlainText()
    

    There is also the toHtml() method. For even more options, you can work directly with the QTextDocument from QTextEdit.document().