QWebview, alignment issue while printing the content to the printer.

  • Hi all,

    Your advice will be really appreciatible.

    I am doing the following:

    I have a class derived from QWebView, and trying to pass the View to the printer.

    My HTML Code:

    @<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>I am a title</title>
    <label> i am a label</label>
    <table border="8px">
    <td bgcolor="red">add</td>

    <td><table border="2px" bgcolor="green" >
    td bgcolor="yellow">Hi i am just a String</td>



    Here is my Qt Code:

    @ QPrinter printer;

     settings()->setAttribute(QWebSettings::PrintElementBackgrounds, true);
     settings()->setAttribute(QWebSettings::JavaEnabled, true);
     settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
     settings()->setAttribute(QWebSettings::AutoLoadImages, true);
      QPrintDialog *dlog = new QPrintDialog (&printer, this);
      qDebug () <<" Printing... ";
      if ( dlog->exec &#40;&#41;  != QDialog::Accepted)
          qDebug () <<"Printing Not accepted.. :( ";



    The output is displayed properly in the QWebView Page, but while printing, the text alignment going for a toss.

    Kindly suggest if i missed out something or need to add more ?..

    Also, i am not sure if the above problem relates to this issue ?


  • I have the same problem!
    Let's find a workaround!

    My workaround consist on saving the rendereded HTML to image. But i am blocked in printing the image!

  • I have the same problem, too.
    I am using:
    Win7 x64
    Qt 5.1 (x32, x64)

    Apparently QWebView has a problem with <TABLE> tag in Qt5.1.
    My program works fine with Qt 4.8.4.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.