开发者

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.


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


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜