Results 1 to 2 of 2

Thread: QTextEdit: About letting Qt stop modifying HTML text

  1. #1
    Join Date
    Sep 2013
    Qt products
    Unix/X11 Windows

    Default QTextEdit: About letting Qt stop modifying HTML text

    Hi all,

    Suppose that you have the following code fragment:
    Qt Code:
    1. QTextEdit textEdit;
    3. textEdit.setHtml("<h2>Description</h2>\n<p>More Details Here</p>");
    5. std::cout << "textEdit.toHtml() = " << textEdit.toHtml().toStdString() << std::endl << std::endl;
    To copy to clipboard, switch view to plain text mode 

    The output is displayed as expected. But the HTML format is as follows (from std::cout):
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "">
    <html><head><meta name="qrichtext" content="1" /><style type="text/css">
    p, li { white-space: pre-wrap; }
    </style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
    <p style=" margin-top:16px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:x-large; font-weight:600;">Description</span></p>
    <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">More Details here.</p></body></html>
    My question is: Is there anyway for keeping the original HTML tags? When I tried to remove the first line (<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "">) using designer or by code, I still get the HTML format that qt forces to be. I know that the displayed rendered text is correct. But my concern is to keep original HTML text untouched (for another application that takes that text from Qt application and the former crashes due to different standard text coming from Qt).

    Many thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Graz, Austria
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Unix/X11 Windows

    Default Re: QTextEdit: About letting Qt stop modifying HTML text

    QTextEdit, or rather its internal QTextDocument, parses the given HTML and creates a document structure for rendering it.
    Like browsers do when they create their DOM tree.

    When you export to HTML each engine will take its current internal representation and create the closest HTML for that.

    If you want to keep the original HTML, keep the original HTML


Similar Threads

  1. QTextEdit with html - rich text issue
    By kuku83 in forum Qt Programming
    Replies: 1
    Last Post: 23rd August 2012, 11:34
  2. Inserting html and plain text in QTextEdit
    By alexandernst in forum Newbie
    Replies: 8
    Last Post: 13th April 2010, 19:53
  3. How to convert text to HTML in QTextEdit
    By Roszko in forum Newbie
    Replies: 5
    Last Post: 31st December 2009, 09:40
  4. Replies: 2
    Last Post: 24th January 2009, 18:30
  5. put html text into a qtextedit
    By dreamer in forum Qt Programming
    Replies: 2
    Last Post: 8th May 2008, 19:44

Tags for this Thread


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.