PDA

View Full Version : QTextEdit content type?



BreakBad
27th June 2012, 19:35
I'm returning a QTextEdit from my delegate when editing a cell in a view. To populate it I call QTextEdit.setPlainText('example string'). However, nothing is displayed in the text area. Printing out QTextEdit.toPlainText() does show the string I pass in. Why is it then not displaying?

I found this is the API under the plainText property:

If the text edit has another content type, it will not be replaced by plain text if you call toPlainText().

But I see nothing about setting the QTextEdit's content type. I've also tried setText and using QTextBrowser.

tyvm,

BB

wysota
27th June 2012, 20:11
Show us your code.

BreakBad
27th June 2012, 20:18
def createEditor(self,parent,option,index):
node = self.getNode(index)
return ElementTextEdit(node._obj,parent=parent)




class ElementTextEdit(QtGui.QTextEdit):
def __init__(self,element,parent=None):
super(ElementTextEdit,self).__init__(parent)

self.element = element

if self.element.text is not None:
self.setPlainText(self.element.text)
print 'toPlainText',self.toPlainText()


edit: Also note I call this on the delegate's parent QTableView widget:


##
#@brief
#@return
#
def persist_editors(self):
for i in xrange(self.model().rowCount(self.rootIndex())):
self.openPersistentEditor(self.model().index(i,1,s elf.rootIndex()))

wysota
27th June 2012, 20:29
Setting the text in the constructor of the widget will not work since the delegate will overwrite it by calling setEditorData on the returned widget.

BreakBad
27th June 2012, 20:34
Setting the text in the constructor of the widget will not work since the delegate will overwrite it by calling setEditorData on the returned widget.


I did not implement setEditorData, and I have other widgets(QLineEdit,QDateEdit,etc..) that work fine when setting the value in the constructor.

However, after implementing:


def setEditorData(self,editor,index):
pass


It works. Which makes me wonder why the other widgets where not overwritten aswell? I suppose the default implementation of setEditorData only worked with QTextEdit....

Thanks again.

wysota
27th June 2012, 20:38
I don't know what you did with the other widgets so I can't clear your doubts. You can always look into Qt's source code and see for yourself.