Results 1 to 9 of 9

Thread: how works Qtextedit?

  1. #1
    Join Date
    Feb 2013
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default how works Qtextedit?

    Hi, all,
    Anybody, who knows how QTextEdit works, help, please.
    I declared
    QTextEdit td;

    I have an html file, I wanna do operation td.setHtml,
    immediately after that I called qDebug() << td.toHtml();

    But this is not the same html, I began to work. It's content has been drastically changed - some content just disappeared, how it maybe?
    Is their any rules, how to prepare html?

    Qt 4.8.x.

    Yours,
    Radmir

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,521
    Thanked 278 Times in 273 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how works Qtextedit?

    Just look at QTextEdit doc and read what is supported HTML subset

  3. #3
    Join Date
    Feb 2013
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how works Qtextedit?

    Quote Originally Posted by Lesiok View Post
    Just look at QTextEdit doc and read what is supported HTML subset
    Not an answer, all tags are from supported set. After <body> there is simple text with its title in <h3> tags and all this upto first <ul> tag dissappears after that operation.

    Radmir

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how works Qtextedit?

    QTextEdit td;
    If this is the code,, then td will be deleted once out of scope.

    Declare on heap.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how works Qtextedit?

    Quote Originally Posted by radmir View Post
    But this is not the same html, I began to work. It's content has been drastically changed - some content just disappeared, how it maybe?
    What kind of content did disappear?

    My guess is that the text edit parses the HTML and creates is internal QTextDocument from it. When you call toHtml() it generates new HTML based on that document.

    So a roundtrip might not yield the exact document, but it should have the same or very similar rendering.

    Cheers,
    _

  6. #6
    Join Date
    Feb 2013
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how works Qtextedit?

    Quote Originally Posted by aamer4yu View Post
    If this is the code,, then td will be deleted once out of scope.

    Declare on heap.
    So, what?
    All this is inside one block of code. So, how your actual remark explains the phenomena?

    Radmir.
    Last edited by radmir; 13th August 2014 at 18:44.

  7. #7
    Join Date
    Feb 2013
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how works Qtextedit?

    Quote Originally Posted by aamer4yu View Post
    If this is the code,, then td will be deleted once out of scope.

    Declare on heap.
    So, what?
    All this is inside one block of code. So, how your actual remark explains the phenomena?

    Radmir.


    Added after 5 minutes:


    Here is an example:
    initial html string is:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"><html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>

    <p>this is the first string.</p>
    <h2>Introduction.</h2>
    <div>This sample build for testing purposes.</div>

    <div><!--StartFragment-->This is second string before content<h2>Content:</h2>
    <div>
    <ul>
    <li><b>Reference="#intro" is used for link to Introduction</b><br /></li>
    <li><b>Reference="#how" is used to Chapter How it was done</b></li>
    </ul></div>
    This is a place for anchor How it was done
    <h3>The Chapter How it was done?</h3>
    <div>It was done witout any sound
    </div>
    </div>

    </body></html>
    td.toHtml() gives:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
    <html><head><meta name="qrichtext" content="1" /><style type="text/css">
    p, li { white-space: pre-wrap; }
    </style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;">
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This is second string before content</p>
    <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;">Content:</span> </p>
    <ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Reference=&quot;#intro&quot; is used for link to Introduction</span><br /></li>
    <li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Reference=&quot;#how&quot; is used to Chapter How it was done</span> </li></ul>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This is a place for anchor How it was done </p>
    <p style=" margin-top:14px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:large; font-weight:600;">The Chapter How it was done?</span> </p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">It was done witout any sound </p></body></html>
    The result lost three strings:
    <p>this is the first string.</p>
    <h2>Introduction.</h2>
    <div>This sample build for testing purposes.</div>

    If you cut theese strings and paste them before tag </body> you will see them again!!!

    How it may be?
    My rests of brains are boiled!

    Radmir

  8. #8
    Join Date
    Feb 2013
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how works Qtextedit?

    Yes I guess so, may you say what really happened in the sample below in my addition yesterday, 22:52?
    Radmir

  9. #9
    Join Date
    Feb 2013
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how works Qtextedit?

    To see all text one should insert the comment <!--StartFragment--> after tag <body>. Be cautious - inserting closing comment <!--EndFragment--> may produse text truncating!?

    Can anybody explain this effect?

    Radmir

Similar Threads

  1. Replies: 0
    Last Post: 24th April 2014, 09:54
  2. QTextEdit - margins, indents within QTextEdit
    By Acamapichtli in forum Newbie
    Replies: 12
    Last Post: 9th April 2014, 18:37
  3. Replies: 3
    Last Post: 6th July 2011, 07:59
  4. QTextEdit parenthesis matcher works - but only partially
    By heinzkde in forum Qt Programming
    Replies: 2
    Last Post: 31st May 2010, 13:31
  5. Replies: 1
    Last Post: 16th February 2007, 08:22

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.