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. QTextDocument (html) print problems
Forum Updated to NodeBB v4.3 + New Features

QTextDocument (html) print problems

Scheduled Pinned Locked Moved General and Desktop
17 Posts 2 Posters 5.2k 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.
  • M Offline
    M Offline
    mschmit
    wrote on last edited by mschmit
    #1

    Hello,

    I tried to print a html file via QTextDocument.

    I use following code:

    QTextDocument *doc = new QTextDocument();
    doc->setHtml(htmlContent);
    doc->print(printer);
    

    The result is not that what i expect.
    See the attachment.

    https://drive.google.com/file/d/0ByPfRL92bgFrM1IxblQwNk56M28/view?usp=sharing

    https://drive.google.com/file/d/0ByPfRL92bgFrVVJXbktmNFNLQVk/view?usp=sharing

    mrjjM 1 Reply Last reply
    0
    • M mschmit

      Hello,

      I tried to print a html file via QTextDocument.

      I use following code:

      QTextDocument *doc = new QTextDocument();
      doc->setHtml(htmlContent);
      doc->print(printer);
      

      The result is not that what i expect.
      See the attachment.

      https://drive.google.com/file/d/0ByPfRL92bgFrM1IxblQwNk56M28/view?usp=sharing

      https://drive.google.com/file/d/0ByPfRL92bgFrVVJXbktmNFNLQVk/view?usp=sharing

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @mschmit
      Hi. Sorry but image upload is broken. we cannot see it. Please use external site :)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mschmit
        wrote on last edited by
        #3

        thx
        now i use an external link

        1 Reply Last reply
        1
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Super.
          You should look at the doc on screen and see if same is shown.
          If yes, it means that QTextDocument and you
          do not agree how the HTML should be rendered :)

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mschmit
            wrote on last edited by
            #5

            Have you ever seen this problem?

            mrjjM 1 Reply Last reply
            0
            • M mschmit

              Have you ever seen this problem?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @mschmit
              Nope. Looks like footer is up in data or something?
              Does it also do this on screen?

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mschmit
                wrote on last edited by
                #7

                no the data is in the footer/header. it just happens if the cell data has more than one row.
                the last than splitts onto two pages

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi
                  But it only splits to other page if page is full?
                  It sounds like expected action. It will not reduce font size to
                  make it fit :)

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mschmit
                    wrote on last edited by
                    #9

                    it splits the cell at the left ( Date ).

                    Expected result:

                    1. change font size
                    2. move last row to the next page
                    mrjjM 1 Reply Last reply
                    0
                    • M mschmit

                      it splits the cell at the left ( Date ).

                      Expected result:

                      1. change font size
                      2. move last row to the next page
                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @mschmit
                      Hi, as far as I know it will only scale fonts based on DPI and not
                      text widths etc.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mschmit
                        wrote on last edited by
                        #11

                        Do you have a workarround for me?
                        Is there a other class/option to print html files?

                        mrjjM 1 Reply Last reply
                        0
                        • M mschmit

                          Do you have a workarround for me?
                          Is there a other class/option to print html files?

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @mschmit
                          Sorry, no. Not really.
                          Only option is to tweak the html.
                          You can also render the widget to bitmap and control the size but that is not good quality.

                          We are in different time zones here on forum
                          so give it a day.
                          There might be someone that have seens this and found something for it. :)

                          mrjjM 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            @mschmit
                            Sorry, no. Not really.
                            Only option is to tweak the html.
                            You can also render the widget to bitmap and control the size but that is not good quality.

                            We are in different time zones here on forum
                            so give it a day.
                            There might be someone that have seens this and found something for it. :)

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            Oh btw
                            You can test with
                            doc.setPageSize(paperSize)
                            and maybe get other results.

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              mschmit
                              wrote on last edited by
                              #14

                              I tried to compile the tool with qt 5.7.

                              It looks better but the last row on the page is splitted onto 2 pages.
                              the css-prop word-break:keep-all does not work :-(

                              https://drive.google.com/file/d/0ByPfRL92bgFrOUFkTS1mXzJLbHc/view?usp=sharing

                              mrjjM 1 Reply Last reply
                              1
                              • M mschmit

                                I tried to compile the tool with qt 5.7.

                                It looks better but the last row on the page is splitted onto 2 pages.
                                the css-prop word-break:keep-all does not work :-(

                                https://drive.google.com/file/d/0ByPfRL92bgFrOUFkTS1mXzJLbHc/view?usp=sharing

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                @mschmit
                                Does look better :)

                                Only a subset is supported. QTextDocument is NOT a browser.
                                http://doc.qt.io/qt-5/richtext-html-subset.html

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  mschmit
                                  wrote on last edited by
                                  #16

                                  I hava a solution :-)

                                  the problem is the css attribute "vertical-align:middle"

                                  i remove this entry and so i have my workaround.

                                  But i think this is a bug. From my point of view splitted rows shoud change to "vertical-align:top"

                                  https://drive.google.com/file/d/0ByPfRL92bgFrek0wbmJxME4ySXM/view?usp=sharing

                                  mrjjM 1 Reply Last reply
                                  1
                                  • M mschmit

                                    I hava a solution :-)

                                    the problem is the css attribute "vertical-align:middle"

                                    i remove this entry and so i have my workaround.

                                    But i think this is a bug. From my point of view splitted rows shoud change to "vertical-align:top"

                                    https://drive.google.com/file/d/0ByPfRL92bgFrek0wbmJxME4ySXM/view?usp=sharing

                                    mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    @mschmit
                                    Super good work!
                                    Well I not sure it will ever change the html on the fly.
                                    It will simply render it as it sees it.
                                    BUt this will be most useful to others.

                                    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