简体   繁体   中英

how to control html code styling in Qprinter

i have a problem with styling html code for printing

i have html file with css code

i read this file like so

void Vente::print_Facture()
{
    QString html;
    QFile reportfile("E:/apprendreQt/gestionstock6/includes/reports/facture.html");

    if ( ! reportfile.open(QIODevice::ReadOnly | QIODevice::Text) ) {
        return;
    }
    html = reportfile.readAll();
    replaceHtml(html);

}

then replace html function replace some words in html ( witch mean i'm using the file as template and fill it with data from database )

void Vente::replaceHtml(QString &html)
{
    // get vente id
    int num_bl = ui->numeroBLlineEdit->text().toInt() ;
    QString requette = "SELECT  produits.designation,produits_en_ventes.qte_out,produits_en_ventes.prix,(produits_en_ventes.qte_out * produits_en_ventes.prix) as montant from ventes left join produits_en_ventes on ventes.vente_id = produits_en_ventes.vente_id left join produits on produits_en_ventes.produit_id = produits.produit_id where ventes.vente_id = :vente_id ";

    if(!m_db->isOpen())
        QMessageBox::critical(this,tr("Inventoria Solution"),m_db->lastError().text()) ;
    else{
        m_query->clear();
        m_query->prepare(requette);
        m_query->bindValue(":vente_id",num_bl);

        if(!m_query->exec())
            QMessageBox::critical(this,tr("Inventoria Solution"),m_query->lastError().text()) ;
        else{
            html = html.replace("%entrepriseNumRegCommerce%","Numéro de registre de commece ")
                    .replace("%entrepriseNumIdenFiscale%","Numéro d'identifiant fiscale")
                    .replace("%numFac%","num facture")
                    .replace("%nomClient%","Nom de client")
                    .replace("%numRegCommerce%","client numéro de registre de commerce")
                    .replace("%numIdenFiscale%","client identifiant fiscale");

            while(m_query->next())
            {
                html +=  "<tr>"

                                 "<td>"+ m_query->value(0).toString() +"</td>"
                                 "<td>"+ QString::number(m_query->value(1).toInt())+"</td>"
                                 "<td>"+ QString::number(m_query->value(2).toInt())+"</td>"
                                 "<td>"+ QString::number(m_query->value(2).toInt())+"</td>"
                                 "</tr>" ;
            }

            html += "</tbody>"
                    "</table>"
                    "<!-- footer of facture -->"
                    "</div>"
                    "</body>"
                    "</html>";
                    print_Html(html);

        }

    }

}

then i print html

void Vente::print_Html( QString &html)
{
    QPrintDialog printDialog(m_printer, this);
    if (printDialog.exec()) {
        QTextDocument textDocument;
        textDocument.setHtml(html);
        textDocument.print(m_printer);
    }

}

the problem is when the print dialog appears and print the html code the styling not works at all

how i can control the postion of html element as well as styling them

您的html应该在受支持的html标记中,我建议您使用xml解析,然后用qdomnode方法替换和更改html标记,也请注意打开和关闭html标记。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM