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;
    painter.begin(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);

    ui->tableStatics->render(painter);@
    

    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.

    "source":http://qt-project.org/doc/qt-5.0/qtprintsupport/qtprintsupport-module.html



  • Thanks,
    Also to make the code correct for later reference, at the end a
    @
    painter->end();
    @

    is missing


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.