Results 1 to 6 of 6

Thread: QPrinter output in portrait instead landscape in windows

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QPrinter output in portrait instead landscape in windows

    Hi,
    I have the following code for printing to pdf a widget:

    Qt Code:
    1. void MainWindow::magToPdf()
    2. {
    3. if(magazineViewer) {
    4. QPrinter printer;
    5. printer.setOrientation(QPrinter::Landscape);
    6. printer.setOutputFileName(magazineViewer->windowTitle() + ".pdf");
    7. printer.setOutputFormat(QPrinter::PdfFormat);
    8. QPixmap qpm = QPixmap::grabWidget(magazineViewer);
    9. if(qpm.isNull()) {
    10. QMessageBox::critical(0, "Error", "Can not capture the window", QMessageBox::Cancel);
    11. return;
    12. }
    13. p.begin(&printer);
    14. p.drawPixmap(85, 32, qpm);
    15. p.end();
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    In linux it works fine: the printed page is in landscape orientation but in windows acrobat shows it in portrait, cutting the right side of the captured widget.

    Is it possible to resolve this behaviour?

    Thanks
    Giuseppe CalÃ

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QPrinter output in portrait instead landscape in windows

    Could you attach a minimal compilable test application? As far as I remember, it worked just fine for me on Windows when I last happened to try.
    J-P Nurmi

  3. #3
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPrinter output in portrait instead landscape in windows

    Here a small code with the same problem; press F8 to print.

    Qt Code:
    1. #include <QApplication>
    2. #include <QDialog>
    3. #include <QtGui>
    4.  
    5. class Dialog: public QDialog
    6. {
    7. Q_OBJECT
    8.  
    9. public:
    10. Dialog(QWidget *parent=0);
    11.  
    12. private:
    13. QLabel *label;
    14. void keyPressEvent(QKeyEvent *event);
    15. void magToPdf();
    16.  
    17. };
    18.  
    19. Dialog::Dialog(QWidget *parent)
    20. :QDialog(parent)
    21. {
    22. label = new QLabel("QT Rules!");
    23. label->setStyleSheet("font-size: 80px");
    24.  
    25. QHBoxLayout *horizontal = new QHBoxLayout;
    26. horizontal->addStretch();
    27. horizontal->addWidget(label);
    28. horizontal->addStretch();
    29.  
    30. QVBoxLayout *vertical = new QVBoxLayout;
    31. vertical->addStretch();
    32. vertical->addLayout(horizontal);
    33. vertical->addStretch();
    34.  
    35. setLayout(vertical);
    36.  
    37. setWindowTitle("Simple QPrint");
    38. setFixedSize(900,667);
    39. }
    40.  
    41. void Dialog::keyPressEvent(QKeyEvent *event)
    42. {
    43. if(event->key() == Qt::Key_F8)
    44. magToPdf();
    45. }
    46.  
    47. void Dialog::magToPdf()
    48. {
    49. QPrinter printer;
    50. printer.setOrientation(QPrinter::Landscape);
    51. printer.setOutputFileName(windowTitle() + ".pdf");
    52. printer.setOutputFormat(QPrinter::PdfFormat);
    53. QPixmap qpm = QPixmap::grabWidget(this);
    54. if(qpm.isNull()) {
    55. QMessageBox::critical(0, "Error", "Can not capture the window", QMessageBox::Cancel);
    56. return;
    57. }
    58. p.begin(&printer);
    59. p.drawPixmap(85, 32, qpm);
    60. p.end();
    61. }
    62.  
    63.  
    64. int main(int argc, char *argv[])
    65. {
    66. QApplication app( argc, argv );
    67. Dialog dialog;
    68. dialog.show();
    69. return app.exec();
    70. }
    71.  
    72. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    Giuseppe CalÃ

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QPrinter output in portrait instead landscape in windows

    Attached PDF was generated with Qt/Win 4.3.2.
    Attached Files Attached Files
    J-P Nurmi

  5. #5
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPrinter output in portrait instead landscape in windows

    In windows I have QT 4.3.1 . Upgrading should solve the problem?
    Giuseppe CalÃ

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QPrinter output in portrait instead landscape in windows

    Sorry, I don't have Qt 4.3.1 installed anymore so I cannot test the difference myself. But as I said, it works for me with Qt 4.3.2.
    J-P Nurmi

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.