Results 1 to 6 of 6

Thread: Trouble to print with QPrintPreviewWidget

  1. #1
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Trouble to print with QPrintPreviewWidget

    Hi friends,

    I'm trying to print some pages from a QPrintPreviewWidget, to call QPrintDialog to set the range of pages want to print, is printed every page, not the range. What I'm doing wrong? Any suggestions?

    Follow small code:

    Report.h
    Qt Code:
    1. class Report: public QMainWindow
    2. {
    3. Q_OBJECT
    4. public:
    5. Report(QWidget *parent = 0, QWidget *widgetReport = 0);
    6. QPrinter *printer;
    7. QPrintPreviewWidget *printPreview;
    8.  
    9. private:
    10. Ui::Report ui;
    11.  
    12. private slots:
    13. void print();
    14. };
    15. #endif
    To copy to clipboard, switch view to plain text mode 

    Report.cpp
    Qt Code:
    1. #include "Report.h"
    2. Report::Report(QWidget *parent, QWidget *widgetReport)
    3. :QMainWindow(parent)
    4. {
    5. ui.setupUi(this);
    6. setAttribute(Qt::WA_DeleteOnClose);
    7. this->showMaximized();
    8.  
    9. printer = new QPrinter(QPrinter::HighResolution);
    10. printer->setOutputFormat(QPrinter::NativeFormat);
    11. printer->setOrientation(QPrinter::Portrait);
    12. printer->setPaperSize(QPrinter::A4);
    13. printer->setFullPage(true);
    14.  
    15. printPreview = new QPrintPreviewWidget(printer, this);
    16. ui.gridLayout1->addWidget(printPreview);
    17.  
    18. connect(ui.ActPrint, SIGNAL(triggered()), this, SLOT(print()));
    19. connect(printPreview, SIGNAL(paintRequested(QPrinter*)), widgetReport, SLOT(Print(QPrinter*)));
    20.  
    21. printPreview->fitInView();
    22. printPreview->show();
    23. }
    24.  
    25. void Report::print()
    26. {
    27. QPrintDialog printDialog(printer, printPreview);
    28. printDialog.setMinMax(1, printPreview->numPages());
    29. if (printDialog.exec() == QDialog::Accepted)
    30. {
    31. qDebug() << printPreview->numPages(); // OK, its return 3 pages, but print all if range is one or two.
    32. printPreview->print();
    33. }
    34. }
    To copy to clipboard, switch view to plain text mode 

    Thanks,

    Marcelo E. Geyer

  2. #2
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: Trouble to print with QPrintPreviewWidget

    It's possible to a bug? Or write my class in a way that these controls will not work? Someone has worked with QPrintPreviewWidget?

  3. #3
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: Trouble to print with QPrintPreviewWidget

    Hi guys, Anybody to help?

  4. #4
    Join Date
    Jan 2006
    Posts
    132
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Trouble to print with QPrintPreviewWidget

    You widgetReport::Print method should read out the the print range and paint accordingly.

  5. #5
    Join Date
    Mar 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trouble to print with QPrintPreviewWidget

    I've got the same problem here. I use pyqt.

    Do you have solution already?

  6. #6
    Join Date
    Dec 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs down Re: Trouble to print with QPrintPreviewWidget

    I've got a similar problem... Qt is too raw to use it in serious projects
    I use .Net and I have never had any problems with printing (and print preview too) text and graphic. Printing is very important for my projects. I tried to convert one of my projects to Qt, but some things are impossible with Qt and some things are not documented as they should be.

Similar Threads

  1. Trouble with QPrintPreviewWidget
    By estanisgeyer in forum Qt Programming
    Replies: 0
    Last Post: 9th December 2008, 13:07

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.