Results 1 to 7 of 7

Thread: QTextEdit html rendering issues

  1. #1
    Join Date
    Aug 2007
    Location
    Fresno - Colombia
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTextEdit html rendering issues

    Hi, i'm trying to render a html file, is a report from a query, with this code:

    Qt Code:
    1. void SalesForm::renderProposal()
    2. {
    3. QString fileName = QDir::currentPath() + "/templates/proposal_template.html";
    4. QFile file(fileName);
    5. if (!file.open(QIODevice::ReadOnly)) {
    6. QMessageBox::warning(this, trUtf8("Error Abriendo Plantilla"),
    7. trUtf8("No se puedo abrir '%1'").arg(fileName));
    8. }
    9.  
    10. QTextStream stream(&file);
    11. QString htmlString;
    12. htmlString = stream.readAll();
    13. QString textEditString = htmlString.arg(propsData.at(0).at(0)).arg(propsData.at(3).at(0)).arg(propsData.at(16).at(0));
    14. propOutTextEdit->setHtml(textEditString);
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    The file loads fine, but the QTextEdit don't render very well the html file, I took a screenshot where the file is loaded
    on Google Chrome and QTextEdit twice.

    htmlQTextEdit.jpg

    html code is shown here:
    http://pastebin.ca/2170961

    I'm not trying to compare Google Chrome with QTextEdit, but the html file is very simple and is made with kompozer.

    Thanks.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QTextEdit html rendering issues

    QTextEdit only supports a subset of HTML that does not specifically mention width styles on table elements. If you want a fully fledged HTML/CSS (read only) experience then use WebKit.

  3. #3
    Join Date
    Aug 2007
    Location
    Fresno - Colombia
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTextEdit html rendering issues

    Thanks,

    But if you look the html code you will see that I don't use CSS or other not supported html subset, for
    example, documentation says:

    table Table Supports the following attributes: border, bgcolor (Qt color names or #RRGGBB), cellspacing, cellpadding, width (absolute or relative), and height.

    My tabable is defined with:
    Qt Code:
    1. <table style="text-align: left; width: 300px; height: 58px;" border="1" cellpadding="2" cellspacing="2">
    2. <tbody>
    3. <tr>
    4. <td style="vertical-align: top; width: 180px;">FORMA DE PAGO<br>
    5. </td>
    6. <td style="vertical-align: top; width: 80px;">%37<br>
    7. </td>
    8. </tr>
    9. <tr>
    10. <td style="vertical-align: top;">VALIDEZ DE LA OFERTA<br>
    11. </td>
    12. <td style="vertical-align: top;">%38<br>
    13. </td>
    14. </tr>
    15. </tbody>
    16. </table>
    To copy to clipboard, switch view to plain text mode 

    And it says too that supports align, but if you see this line, I used supported align set:
    Qt Code:
    1. <div style="text-align: right; font-weight: bold;"><big><big>PROPUESTA COMERCIAL</big></big><br>
    2. </div>
    To copy to clipboard, switch view to plain text mode 
    But in QTextEdit text is shown on the left.
    Thanks again.

  4. #4
    Join Date
    Aug 2007
    Location
    Fresno - Colombia
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTextEdit html rendering issues

    I just used QWebView, including <QtWebKit/QWebView> and the webkit module on my .pro file too.
    Last edited by haldrik; 17th July 2012 at 03:24.

  5. #5
    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 html rendering issues

    Quote Originally Posted by haldrik View Post
    But if you look the html code you will see that I don't use CSS or other not supported html subset
    This:
    html Code:
    1. style="text-align: left; width: 300px; height: 58px;"
    To copy to clipboard, switch view to plain text mode 
    ... is CSS.
    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.


  6. #6
    Join Date
    Aug 2007
    Location
    Fresno - Colombia
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTextEdit html rendering issues

    Ohh, ok, thanks.

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QTextEdit html rendering issues

    Quote Originally Posted by haldrik View Post
    And it says too that supports align, but if you see this line, I used supported align set:
    Qt Code:
    1. <div style="text-align: right; font-weight: bold;"><big><big>PROPUESTA COMERCIAL</big></big><br>
    2. </div>
    To copy to clipboard, switch view to plain text mode 
    Just to reinforce this, this a is "div" element with a "style" attribute containing CSS properties. The supported attributes for this element are "align" and "dir". Even if "style" were supported here, the allowed CSS subset does not include "text-align".

Similar Threads

  1. Arabic text rendering; issues with parentheses
    By TropicalPenguin in forum Qt Programming
    Replies: 4
    Last Post: 10th September 2013, 09:53
  2. HTML Rendering issues when webview transparency enabled
    By Anil V in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 15th June 2012, 07:38
  3. Mac OS QtWebKit CSS3 rendering issues
    By Chirieac in forum Qt Programming
    Replies: 1
    Last Post: 15th April 2012, 20:05
  4. Replies: 0
    Last Post: 30th November 2008, 16:59
  5. Replies: 1
    Last Post: 19th November 2007, 01:34

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.