Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Paint Html formating correctly ?

Paint Html formating correctly ?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 667 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • cfdevC Offline
    cfdevC Offline
    cfdev
    wrote on last edited by
    #1

    Hello there!
    I want to paint a text formating in html, this is what I do :

    QTextDocument HtmlTxt;
    QTextOption textOption;
    QString templateHtml;
    textOption.setAlignment(Qt::AlignJustify);
    textOption.setWrapMode(QTextOption::WordWrap);
    HtmlTxt.setDefaultTextOption(textOption);
    
    templateHtml = "<html><head><style>body{font-size:32px;}</style></head><body>{{%BODY%}}</body></html>";
    
    HtmlTxt.setTextWidth(rect.width());
    HtmlTxt.setHtml( templateHtml.replace("{{%BODY%}}", text );
    painter.save();
    painter.translate(rect.topLeft());
    HtmlTxt.drawContents(&painter);
    painter.restore();
    // Draw below this content but, where I am ?
    

    It's working, but After that I don"t know where is my rect.bottom ? to continue the painter.

    Is it the good way to paint a HTML text ?
    Thanks

    raven-worxR 1 Reply Last reply
    0
    • cfdevC cfdev

      Hello there!
      I want to paint a text formating in html, this is what I do :

      QTextDocument HtmlTxt;
      QTextOption textOption;
      QString templateHtml;
      textOption.setAlignment(Qt::AlignJustify);
      textOption.setWrapMode(QTextOption::WordWrap);
      HtmlTxt.setDefaultTextOption(textOption);
      
      templateHtml = "<html><head><style>body{font-size:32px;}</style></head><body>{{%BODY%}}</body></html>";
      
      HtmlTxt.setTextWidth(rect.width());
      HtmlTxt.setHtml( templateHtml.replace("{{%BODY%}}", text );
      painter.save();
      painter.translate(rect.topLeft());
      HtmlTxt.drawContents(&painter);
      painter.restore();
      // Draw below this content but, where I am ?
      

      It's working, but After that I don"t know where is my rect.bottom ? to continue the painter.

      Is it the good way to paint a HTML text ?
      Thanks

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @cfdev
      note that QTextDocument does only support a rich text HTML subset

      Since you already have a QTextDocument you can query it's size and other properties (like documentMargin, etc)

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      cfdevC 1 Reply Last reply
      1
      • raven-worxR raven-worx

        @cfdev
        note that QTextDocument does only support a rich text HTML subset

        Since you already have a QTextDocument you can query it's size and other properties (like documentMargin, etc)

        cfdevC Offline
        cfdevC Offline
        cfdev
        wrote on last edited by
        #3

        @raven-worx
        note that QTextDocument does only support a rich text HTML subset
        yes I need juste the base formating, <strong>, <ul>, <i>....

        Since you already have a QTextDocument you can query it's size and other properties (like documentMargin, etc)
        Thanks It's what I needed ! ;)

        raven-worxR 1 Reply Last reply
        0
        • cfdevC cfdev

          @raven-worx
          note that QTextDocument does only support a rich text HTML subset
          yes I need juste the base formating, <strong>, <ul>, <i>....

          Since you already have a QTextDocument you can query it's size and other properties (like documentMargin, etc)
          Thanks It's what I needed ! ;)

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @cfdev said in Paint Html formating correctly ?:

          yes I need juste the base formating, <strong>, <ul>, <i>....

          no, you are also using a style tag with CSS in it: <style>body{font-size:32px;}</style>

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved