Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. QWebView not respecting html <thead>
QtWS25 Last Chance

QWebView not respecting html <thead>

Scheduled Pinned Locked Moved Qt WebKit
9 Posts 3 Posters 3.2k Views
  • 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.
  • H Offline
    H Offline
    h1d2
    wrote on last edited by
    #1

    QWebView does not seem to respect <thead> code for tables. Other attributes including CSS that I have tried seem to be working fine.

    Here's what I'm doing:

    Create simple html code for a long table. Html code for table headers are enclosed in <thead></thead> so that they would be repeated when table spans more than one page.

    Assign the html code to a QWebView

    Print the QWebView to pdf using QPrinter

    What I expect is for the headers to be repeated when the table spans more than 1 page. But that's not the case. If I assign the same code to a QTextBrowser, it works fine: the headers are repeated in new pages. But I'd like to use a QWebView since it supports CSS better.

    Only other post related to this I found was "this":http://qtforum.de/forum/viewtopic.php?t=7855 dating back to 2008 (no responses) as well as this "bug":https://bugreports.qt.io/browse/QTBUG-31601 that appears to affect version 5. Any suggestions/guidance/comments would be greatly appreciated. Thanks.

    Some additional info:

    • Using Qt 4.8.2
    • Tried on Linux (Fedora) and Windows 7 (compiled with VS2010)
    • Removed full code below to bypass the "spam" detection

    Edit: I'm including the full code and the images of the resulting pdfs posted in comments for future refereces:

    • full code: http://pastebin.com/e4bmEyV7
    • webViewOutput.pdf: http://i.imgur.com/i47qrdo.png
    • textBrowserOutput.pdf: http://i.imgur.com/XxoC61b.png

    @
    // --------------------------------------------------
    // QWebView approach:
    QWebView webView;
    webView.setHtml( generateHtmlTable(100) );

    printer.setOutputFileName("webViewOutput.pdf");
    webView.print(&printer);
    // --------------------------------------------------

    // --------------------------------------------------
    // QTextBrowser approach:
    QTextBrowser textBrowser;
    textBrowser.setHtml( generateHtmlTable(100) );

    printer.setOutputFileName("textBrowserOutput.pdf");
    textBrowser.print(&printer);
    // --------------------------------------------------
    @

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Subst27
      wrote on last edited by
      #2

      Hi!

      can you publish all code of the html page?

      1 Reply Last reply
      0
      • H Offline
        H Offline
        h1d2
        wrote on last edited by
        #3

        I had it posted, but the page would forum would flag it as spam. So this time I'm putting them else where.

        Here is the full c++ code including the html part: http://pastebin.com/e4bmEyV7

        and here is only the html part: http://pastebin.com/k7BBERHf (there is an extra ``\n'' in one that should be removed)

        Thanks

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Subst27
          wrote on last edited by
          #4

          the html code seems fine and webkit understand it

          http://disk.tom.ru/wuv1df7

          but in your project it don't work? isn't it?
          I think the problem in the generateHtmlTable function.

          well. will be looking for solve

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Subst27
            wrote on last edited by
            #5

            It's funny but your code works fine :o\

            http://disk.tom.ru/nhpmrl1

            @QString htmlCode;

            int numLines=3;
            // Open html tags

            htmlCode =
            "<html>\n"
            " <body>\n"
            ""
            " <table>\n"
            " <thead>\n"
            " <tr>\n"
            " <th> Header 1 </th>\n"
            " <th> Header 2 </th>\n"
            " <th> Header 3 </th>\n"
            " </tr>\n"
            " </thead>\n";

            // Fill rows

            for (int i=0; i<numLines; ++i){
            htmlCode +=
            "<tr>\n";
            htmlCode += QString("<td> %0 </td>\n").arg(i);
            htmlCode += QString("<td> %0 </td>\n").arg(i+1);
            htmlCode += QString("<td> %0 </td>\n").arg(i+2);
            htmlCode +=
            "</tr>\n";
            }

            // Close tags

            htmlCode +=
            "</table>\n"
            "</body>\n"
            "</html>\n"
            ;
            qDebug()<<htmlCode;
            textBrowser->setHtml(htmlCode);
            webView->setHtml(htmlCode);

            QPrinter printer;
            printer.setOutputFormat(QPrinter::PdfFormat);
            printer.setOutputFileName("d:/2.pdf");
            webView->print(&printer);@

            1 Reply Last reply
            0
            • T Offline
              T Offline
              ThatDude
              wrote on last edited by
              #6

              I don't see a proper TBODY tag...

              "According to this description":https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tbody TBODY tag is responsible for printing THEAD and TFOOT on every page
              https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tbody

              (<tbody>) provides additional semantic information for devices such as printers and displays. Of the parent table's child elements, (<tbody>) will represent the content, if longer than a page, that will most likely differ for each page printed. The <tfoot> and <thead> elements' content will be consistent for each page printed.

              1 Reply Last reply
              0
              • H Offline
                H Offline
                h1d2
                wrote on last edited by
                #7

                The code compiles and runs fine. The problem is with the <thead> tag not beign respected when the table spans more than 2 pages and printed to pdf. See below for comparison between resulting PDFs generated from the code I posted:

                This is the result from QWebView (webViewOutput.pdf): http://i.imgur.com/i47qrdo.png
                Note the missing headers on second page

                This is the result from QTextBrowser (textBrowserOutput.pdf) which actually respects the <thead> tag:
                http://i.imgur.com/XxoC61b.png
                Note that the headers are automatically repeated on second page.

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  h1d2
                  wrote on last edited by
                  #8

                  [quote author="ThatDude" date="1421162273"]I don't see a proper TBODY tag...

                  [/quote]

                  Thanks for your reply. I tried that, but the result is the same as before.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Subst27
                    wrote on last edited by
                    #9

                    oh, sorry.
                    I think webkit can't recognize the begin and end of page. And TBODY tag (as wrote ThatDude can't help in this case, it's usefull for block formatting)

                    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