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. How to control html code styling in Qprinter
QtWS25 Last Chance

How to control html code styling in Qprinter

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 2.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.
  • A Offline
    A Offline
    advseo32
    wrote on last edited by
    #1

    Hello every one

    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>"
                    "&lt;!-- footer of facture --&gt;"
                    "</div>"
                    "&lt;/body&gt;"
                    "&lt;/html&gt;";
                    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

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      i assume the opening element of the table is the end in your template html file? Meaning is the HTML you want to print at the end valid?

      An advice: save yourself from some pain and don't use QTextDocument when you need HTML features :P
      I would suggest you to use QWebView instead and use it's "print()":http://qt-project.org/doc/qt-5.0/qtwebkit/qwebview.html#print method.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • A Offline
        A Offline
        advseo32
        wrote on last edited by
        #3

        Ok, thank's for advices , but what library should i include to my .pro file

        because i'm getting an error

        E:\apprendreQt\gestionstock6\vente.cpp:595: error: undefined reference to `_imp___ZNK8QWebView5printEP8QPrinter'

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          QtWebkit module

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • A Offline
            A Offline
            advseo32
            wrote on last edited by
            #5

            ok, it works a little bit better then before but i still can't controle the position of element in the page

            i have coded the report page as template it works in firefox every element in the place where i want it , but when i click print button , the position of elements changed , plz tell me witch is the correct way to print using html and Qwebview or other garantate way

            1 Reply Last reply
            0
            • A Offline
              A Offline
              advseo32
              wrote on last edited by
              #6

              i have a porblem like this guy

              http://qt-project.org/forums/viewthread/32643/

              1 Reply Last reply
              0
              • A Offline
                A Offline
                advseo32
                wrote on last edited by
                #7

                Plz any body help me

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  advseo32
                  wrote on last edited by
                  #8

                  I need a printing solution for my project !!

                  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