Congratulations to our 2022 Qt Champions!

Problem with printing

  • Hi all,
    I am trying to print a QTableWidget with QPrinter. When I add #include <QPrinter> the compiler complains that this header does not exist. I found a QPrinter header in <QtPrintSupport/QPrinter> but if I use that then the linker complains "Symbol not found for architecture x86_64. I am using MacBook pro and I also installed the full package of QT. Here is the piece of code I am trying to use (It is completely from documentation with little change)
    @ QPainter painter;
    QPrinter printer;
    double xscale = printer.pageRect().width()/double(ui->tableStatics->width());
    double yscale = printer.pageRect().height()/double(ui->tableStatics->height());
    double scale = qMin(xscale, yscale);
    painter.translate(printer.paperRect().x() + printer.pageRect().width()/2,
    printer.paperRect().y() + printer.pageRect().height()/2);
    painter.scale(scale, scale);
    painter.translate(-width()/2, -height()/2);


    Any help is appreciated.

  • In Qt5 the printing module is separated.

    QT += printsupport

  • Could you please give more details or an example

  • Add the "QT += printsupport" to your .pro file.


  • Thanks,
    Also to make the code correct for later reference, at the end a

    is missing

Log in to reply