Results 1 to 6 of 6

Thread: QTextEdit content type?

  1. #1
    Join Date
    Jun 2012
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X

    Question QTextEdit content type?

    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
    Last edited by BreakBad; 27th June 2012 at 18:50.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit content type?

    Show us your code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2012
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QTextEdit content type?

    Qt Code:
    1. def createEditor(self,parent,option,index):
    2. node = self.getNode(index)
    3. return ElementTextEdit(node._obj,parent=parent)
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. class ElementTextEdit(QtGui.QTextEdit):
    2. def __init__(self,element,parent=None):
    3. super(ElementTextEdit,self).__init__(parent)
    4.  
    5. self.element = element
    6.  
    7. if self.element.text is not None:
    8. self.setPlainText(self.element.text)
    9. print 'toPlainText',self.toPlainText()
    To copy to clipboard, switch view to plain text mode 

    edit: Also note I call this on the delegate's parent QTableView widget:
    Qt Code:
    1. ##
    2. #@brief
    3. #@return
    4. #
    5. def persist_editors(self):
    6. for i in xrange(self.model().rowCount(self.rootIndex())):
    7. self.openPersistentEditor(self.model().index(i,1,self.rootIndex()))
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit content type?

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    BreakBad (27th June 2012)

  6. #5
    Join Date
    Jun 2012
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QTextEdit content type?

    Quote Originally Posted by wysota View Post
    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:
    Qt Code:
    1. def setEditorData(self,editor,index):
    2. pass
    To copy to clipboard, switch view to plain text mode 

    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.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit content type?

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 7
    Last Post: 19th April 2011, 12:20
  2. Replies: 1
    Last Post: 24th March 2011, 16:40
  3. Reply Header - Content-Type
    By seink in forum Newbie
    Replies: 2
    Last Post: 16th December 2010, 17:11
  4. Replies: 2
    Last Post: 22nd December 2009, 20:52
  5. Replies: 6
    Last Post: 17th January 2008, 23:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.