ThreaderSlash
ThreaderSlash

Reputation: 1313

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.

Upvotes: 1

Views: 6403

Answers (3)

gnud
gnud

Reputation: 78528

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().

Upvotes: 5

gruszczy
gruszczy

Reputation: 42188

Method show from widget is used to display the widget on a screen. For example if you have main window, you call show to display it to user. If you wish to retrieve data from some edit, be it line edit or text edit, you should use text() method. Like this:

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

Upvotes: 0

Bruno Oliveira
Bruno Oliveira

Reputation: 15255

Your showInput method is printing the return from the show() method, which returns None. If you want to print the current text in the edit, use:

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

Upvotes: 0

Related Questions