Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QPrintPreviewDialog does not show arabic caracters correctly



  • Hi there,
    I am coding an application, that needs to print some papers in arabic, the problem is that QPrintPreviewDialog widget that I use does not show arabic caracters correctly.
    I read html data from a QFile, with QTextStream, I set the codec to html UTF-8, set it to QTextDocument with setHtml() method, and send this document to the printer device with drawContents() method, because the print () method would not work with me.

    void AjoutOffre::imprimer(QPrinter *printer)
    {
        QTextDocument *file= new QTextDocument();
        QFile fichier("contrat.html");
        fichier.open(QIODevice::ReadOnly);
        QTextStream string(&fichier);
        QString html;
        string.setCodec(QTextCodec::codecForHtml("UTF-8"));
        file->setHtml(string.readAll());
        html=string.readAll();
        QMessageBox::information(this,"Titre",QString::number(html.count()));
        BonDeVisite *myWidget= new BonDeVisite();
        QPainter painter(printer);
            painter.setRenderHints(QPainter::Antialiasing |
                               QPainter::TextAntialiasing |
                               QPainter::SmoothPixmapTransform, true);
    
        file->drawContents(&painter);
    }
    void AjoutOffre::on_toolButton_clicked()
    
    {
                QPrinter *printer= new QPrinter();
                printer->setPaperSize(QPrinter::A4);
                printer->setOutputFileName("html.pdf");
                printer->setPageMargins(12, 16, 12, 20, QPrinter::Millimeter);
                printer->setFullPage(false);
                QPrintPreviewDialog *fen= new QPrintPreviewDialog(printer,this);
                QObject::connect(fen,SIGNAL(paintRequested(QPrinter*)),this,SLOT(imprimer(QPrinter*)));
                fen->show();
    }
    

    Any ansewrs please??


Log in to reply