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. Using QPrintPreviewWidget to preview pages with different orientation or paper ?

Using QPrintPreviewWidget to preview pages with different orientation or paper ?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.1k 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.
  • M Offline
    M Offline
    max2g
    wrote on last edited by
    #1

    Hi !

    I search for information but found nothing about how to preview a set of pages, some of which are portrait while others ar landscape. If I change the QPrintPreviewWidget orientation while in the slot, the orientation is not changed and remains what it was at the first call.

    Here is the part of the code which is a simple test to print something on many pages with some portrait and some landscape. Note that what is being print by that example is not important. Focus on the if statement.

    @void MainWindow::print2Slot(QPrinter *printer)
    {
    QPixmap image("C:/Users/DELL_02/Desktop/image.png");

    QPainter painterPrinter(printer);
    
    qreal x = 0;
    qreal y = 0;
    
    for (int iPage = 0; iPage < 5; iPage++)
    {
        if ((iPage % 2) == 0)
            printer->setOrientation(QPrinter::Portrait);
        else
            printer->setOrientation(QPrinter::Landscape);
    
        x = iPage * 100.0 * printer->resolution() / 90;
        y = iPage * 100.0 * printer->resolution() / 90;
    
        QRectF rectangleS(x, y, 100, 100);
    
        painterPrinter.drawImage(rectangleS, image.toImage(), rectangleS);
        if (iPage < 4) printer->newPage();
    }
    

    }
    @

    Thank you !

    1 Reply Last reply
    0
    • S Offline
      S Offline
      ScottR
      wrote on last edited by
      #2

      I don't see the code using a QPrintPreviewWidget.

      Maybe you need to refactor it so that the QPainter object is constructed with the QPainter after the orientation is changed?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        max2g
        wrote on last edited by
        #3

        Hi !

        What you see in the code is the slot being called when the QPrintPreviewWidget emit a signal for update.

        The problem has been adressed but not really solved since I learn from Digia that changing paper orientation while in preview is not yet supported. It is however a feature requested but there is no timeframe for that futur feature !!!

        The only workaround is to build one page at a time, ensuring that the printer is properly set for the right orientation and then use QPrintPreviewWidget to show this page.

        Thank you !

        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