Results 1 to 9 of 9

Thread: Inserting html and plain text in QTextEdit

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Inserting html and plain text in QTextEdit

    I don't understand. Why don't you just add it as html? The same text. Just the other method. Does it work then?

  2. #2
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Inserting html and plain text in QTextEdit

    No, it woesn't work
    Could you try it to be sure?

  3. #3
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Inserting html and plain text in QTextEdit

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6.  
    7. QTextCursor cursor = te.textCursor();
    8. cursor.insertHtml("<a href='http://www.w3schools.com/'>Link!</a>oops<br>");
    9. cursor.insertHtml("<a href='http://www.w3schools.com/'>Link!</a>");
    10. cursor.insertHtml("something");
    11. cursor.insertHtml("<br>");
    12. cursor.insertHtml("<a href='http://www.w3schools.com/'>Link!</a>");
    13. cursor.insertText("something");
    14. te.show();
    15. return a.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 
    LinkEdit..png
    So you are right.. this is unexpected beviour. But inserting as html seems to work..

    BTW:
    Qt Code:
    1. self.cursor = QTextCursor(self.textArea.document())
    To copy to clipboard, switch view to plain text mode 
    Is this correct for PyQt? Seems strange to me.

    Johannes
    Last edited by JohannesMunk; 13th April 2010 at 19:38.

  4. #4
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Inserting html and plain text in QTextEdit

    I guess I'll be using only .insertHtml

    About the self.cursor = QTextCursor(self.textArea.document())

    textArea is a QTextEdit, and .document() returns a QTextDocument.
    On the other hand, QTextCursor can be initialized with a QTextDocument, so, yes, it's correct (at least according to docs )
    QTextCursor can also be inialized with QTextFrame, QTextCursor or without args.


    Thanks for the help

Similar Threads

  1. How to convert text to HTML in QTextEdit
    By Roszko in forum Newbie
    Replies: 5
    Last Post: 31st December 2009, 09:40
  2. put html text into a qtextedit
    By dreamer in forum Qt Programming
    Replies: 2
    Last Post: 8th May 2008, 19:44
  3. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 16:45
  4. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  5. Problem with inserting text into QTextEdit
    By xorrr in forum Qt Programming
    Replies: 0
    Last Post: 6th February 2006, 11:45

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.