Results 1 to 5 of 5

Thread: Rotating Printing of QGraphicsScene

  1. #1
    Join Date
    Jan 2006
    Posts
    22
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Rotating Printing of QGraphicsScene

    Hello all,

    I'm working on a program that needs to print images of documents, and I'm stumped on how to rotate the contents to print sideways, so as to fill all available space. In my scene, I have an image (which defines the size of the scene) and various primitives. Centering and scaling the document in proportion on the page are my goals, but getting this to work would be a great start. The code I'm trying here only moves the image partway in from the left, cutting off part of it. Any ideas?

    Qt Code:
    1. bool AreaWindow::showPrintDialog() {
    2. QPrinter printer(QPrinter::HighResolution);
    3. QPrintDialog printDialog(&printer, this);
    4. printDialog.setMinMax(1, 1);
    5. if (printDialog.exec() == QDialog::Accepted) {
    6. QPainter painter(&printer);
    7. if (image.width() > image.height()) {
    8. painter.rotate(90);
    9. painter.translate(0, -image.height());
    10. }
    11. scene->render(&painter);
    12. return true;
    13. }
    14. return false;
    15. }
    To copy to clipboard, switch view to plain text mode 
    ImageRocket - My Qt4-based image editing program
    Project Page / Screenshots / Source

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Rotating Printing of QGraphicsScene

    QPainter::setWindow() and QPainter::setViewport() are your friends for the task. Or QPainter::scale() if you want to calculate the scale yourself.

  3. #3
    Join Date
    Jan 2006
    Posts
    22
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotating Printing of QGraphicsScene

    Thanks for the suggestion, wysota, but I've worked on it for hours and haven't made any progress using them. For the present situation, I assumed that setWindow would work to bring the rotated image back into view by setting the window to (-image.width(), 0, image.width(), image.height()). I've tried this followed by rotating it 90 degrees (blank page) or rotating to 80 (a rotated piece of the image, with it cutting short in midair). I realize I need to set it properly to keep aspect, but I'm not worrying about that yet. I'd also really like to know why "painter.translate(0, -image.height());" isn't enough.
    ImageRocket - My Qt4-based image editing program
    Project Page / Screenshots / Source

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Rotating Printing of QGraphicsScene

    Could be that your printer has different horizontal and vertical resolution or your scene has different proportions than the paper.

  5. The following user says thank you to wysota for this useful post:

    init2null (22nd March 2008)

  6. #5
    Join Date
    Jan 2006
    Posts
    22
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotating Printing of QGraphicsScene

    Well, I still don't have an answer as to why rotating doesn't work. I don't think the problem is resolution- or aspect-related, but I think I've found a way to circumvent it by just using QPrinter::setOrientation. It seems to do everything I need it to do, including scaling. I should've found it sooner, but I got stuck thinking along this path. Thanks for your help though!
    ImageRocket - My Qt4-based image editing program
    Project Page / Screenshots / Source

Similar Threads

  1. Printing problem in windows
    By joseph in forum Qt Programming
    Replies: 6
    Last Post: 12th July 2007, 08:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.