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. Printing in custom size
Qt 6.11 is out! See what's new in the release blog

Printing in custom size

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 755 Views 2 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.
  • W Offline
    W Offline
    wazzdaman
    wrote on last edited by
    #1

    Hello,

    I have a QGraphicsScene with scene size of 4"x6" and I'd like print it in the same size. Unfortunately it gets scaled up to the paper size. How can I print it with the correct size (regardless of the used paper size)?

    When I tried to set up the custom page size I got only an empty page :(

    Win 10, Qt 5.15.2

    QPageSize pageSize = QPageSize(QSizeF(4.0, 6.0), QPageSize::Unit::Inch, "4x6 in page", QPageSize::SizeMatchPolicy::ExactMatch);
    bool result = printer.setPageSize(pageSize);
    qDebug() << "page set result" << result; // true 
    qDebug() << printer.pageLayout().pageSize().name(); // "4x6 in page"
    qDebug() << printer.pageLayout().pageSize().id(); // 30 - ID of custom page size
    printer.setPageOrientation(QPageLayout::Landscape);
    QPainter painter(&printer);
    painter.setRenderHint(QPainter::Antialiasing);
    workScene->render(&painter); 
    

    Any help is appreciated. Thanks!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What do you get if you paint a rectangle rather than your scene ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • W Offline
        W Offline
        wazzdaman
        wrote on last edited by wazzdaman
        #3

        @SGaist If I replace the line

        workScene->render(&painter); 
        

        with

        painter.begin(printer);
        painter.drawRect(QRectF(0, 0, 100, 100));
        painter.end();
        

        then I get a little rectangle in the corner, although it complains that

        QPainter::begin: A paint device can only be painted by one painter at a time.
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Since you passed printer to QPainter's constructor, you shall not call begin, just end.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • W Offline
            W Offline
            wazzdaman
            wrote on last edited by
            #5

            @SGaist It fixed that warning message, thanks!

            I think I've found the solution for my problem: I should pass the correct size for target in QGraphicsScene::render() and it will render the scene correctly regardless of the paper size. Is this correct?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Sounds good.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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