[QTextDocument] Alignement in impression



  • Hello, I want to print a html document.
    I use a QTextDocument, the html document contains css which have to align the text in the middle of the page
    My code :
    @
    QPrinter *printer = new QPrinter;
    printer->setPageSize(QPrinter::A4);
    qDebug() << "After printer";
    QPrintDialog *dialogue = new QPrintDialog(printer);
    qDebug() << "After creation printdialog";
    dialogue->exec();
    QWebView *web = new QWebView;
    QFile fichier(QCoreApplication::applicationDirPath() + "/data/max.html");
    fichier.open(QIODevice::ReadOnly);
    web->settings()->setUserStyleSheetUrl(QUrl::fromLocalFile(QCoreApplication::applicationDirPath() + "/style.css"));
    web->setHtml(fichier.readAll());
    web->show();
    web->setMinimumSize(500, 1000);
    QTextDocument test;
    QFile test2(QCoreApplication::applicationDirPath() + "/style.css");
    QString style(test2.readAll());
    style.append("\n</style>");
    style.prepend("<style>\n");
    QFile test3(QCoreApplication::applicationDirPath() + "/data/max.html");
    test3.open(QIODevice::ReadOnly);
    test.setHtml(style + test3.readAll());
    test.print(printer);
    @

    My html code :

    @
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" http-equiv="Content-Type" content="text/html"/>
    <link rel="stylesheet" content="text/css" href="..\style.css"/>
    </head>
    <body>
    <h1>Max</h1>
    <h2 id="0"></h2>
    <div>Langue : Fdfs</div>
    <table>
    <thead>
    <tr>
    <th>Termes</th>
    <th>Traductions</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>fsqd</td>
    <td>fqd</td>
    </tr><tr>
    <td>fsdqf</td>
    <td>sdqf</td>
    </tr><tr>
    <td>g</td>
    <td> </td>
    </tr>
    <tr>
    <td>g</td>
    <td></td>
    </tr>
    </tbody>
    </table>
    </body>
    </html>
    @

    My CSS code :
    @
    h1
    {
    font-size: 20;
    font-family: Arial;
    font-weight: false;
    font-italic: false;
    color: rgba(255, 0, 0, 255);
    text-align: center;
    }
    h2
    {
    font-size: 15;
    font-family: Arial;
    font-weight: false;
    font-italic: false;
    color: rgba(0, 0, 0, 255);
    text-align: center;
    }
    div
    {
    font-size: 12;
    font-family: Arial;
    font-weight: false;
    font-italic: false;
    color: rgba(0, 128, 0, 255);
    text-align: center;
    margin-bottom: 1em;
    }
    th
    {
    font-size: 12;
    font-family: Arial;
    font-weight: false;
    font-italic: false;
    color: rgba(0, 0, 255, 255);
    }
    tbody tr td:first-child
    {
    font-size: 10;
    font-family: Arial;
    font-weight: false;
    font-italic: false;
    color: rgba(255, 165, 0, 255);
    text-align: right;
    }
    tbody tr td:last-child
    {
    font-size: 10;
    font-family: Arial;
    font-weight: false;
    font-italic: false;
    color: rgba(255, 255, 0, 255);
    }
    td, th
    {
    border: solid 1px blue;
    }
    table
    {
    margin-left: auto;
    margin-right: auto;
    border-collapse: collapse;
    }
    @

    And when I print (using PDFCreator), I obtain this :
    !http://img11.hostingpics.net/pics/662739Capture.png(Result)!

    So how can i do to obtain a correct alignement ?

    Note : Excuse my english, i'm french.


Log in to reply
 

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