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

How change FontSize at print



  • Hi!
    How change FontSize at print?
    It's not work:

    void MainWindow::PrintDocument(QString &TextForPrint) //PrintDocument
    {
        QPrinter MyPrinter;
        QPrintDialog *PrinterDialog = new QPrintDialog(&MyPrinter);
        PrinterDialog->setWindowTitle("Print");
        QFont FontForPrint;
        FontForPrint.setPointSize(22);
        //PrinterDialog->setFont(FontForPrint);
        if (PrinterDialog->exec())
        {
            QPainter MyPainter;
            MyPainter.begin(&MyPrinter);
            MyPainter.drawText(100, 100, 400, 400, Qt::AlignLeft|Qt::AlignTop, TextForPrint);
            MyPainter.setFont(FontForPrint);
            MyPainter.end();
        }
    }
    


  • @Mikeeeeee said in How change FontSize at print:

    It's not work:

    Does it change the font ? then u have to take font from QPrinter and then try to modify font.
    Something like this

    QFont font = MyPrinter.font() ;
    

  • Lifetime Qt Champion

    Hi
    You set font After you draw the text.


Log in to reply