Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Images moved while printing the QGraphicsScene

Images moved while printing the QGraphicsScene

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 425 Views
  • 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.
  • V Offline
    V Offline
    Vergess
    wrote on last edited by
    #1

    Hi

    I am experiencing the problem with printing the contents of a QGraphicsScene. I create a printer and a painter using this printer. Then I simply render the QGraphicsScene using this painter. Everything looks fine when I store rendered graphics scene to an image (apart of the fact that the background is green), but when I want to render to a printer, the images from my graphics scene are moved and overlap each over. Text fields seem to be ok. This happens on windows, using microsoft xps document writer, as well as any hardware printer, so I think this is not connected to a specific driver.

    I am printing a care labels for clothes, so paper sizes are small. Typically 40x100mm.

    Any suggestions?? Could this be a QT bug??

    Here is the code that I use:

    QPrinter printer(QPrinterInfo::printerInfo(name));
        printer.setPageMargins(0,0,0,0,QPrinter::Millimeter);
        printer.setResolution(QPrinter::HighResolution);
        printer.setOutputFormat(QPrinter::NativeFormat);
        printer.setFullPage(true);
        printer.setPaperSize(QSizeF((label->getWidth()-2)/pixelToMmMultiplier,(label->getHeight()-2)/pixelToMmMultiplier), QPrinter::Millimeter);
        QPointF mainRectPos = label->getMainRectPos();
        QPainter painter(&printer);
            QRectF sourceRect = QRectF(QPointF(mainRectPos.x()+1, mainRectPos.y()+1),QSizeF(label->getWidth()-2, label->getHeight()-2));
            label->getGraphicsScene()->render(&painter, QRectF(), sourceRect, Qt::IgnoreAspectRatio);
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Yes it could be a bug. :) Often its something else though :)
      That is a bit odd as rendering to screen or printer is very alike in Qt.
      Did you try with setOutputFormat and pdf`?

      Does pic also overlap when pdf?

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