Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with printing
Qt 6.12 LTS is out! See what's new in the release blog

Problem with printing

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.6k Views 1 Watching
  • 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
    ashkan
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      In Qt5 the printing module is separated.

      QT += printsupport

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

        Could you please give more details or an example

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

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

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

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

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

            is missing

            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
            • Unsolved