Results 1 to 1 of 1

Thread: Trouble 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

    Question Trouble with QPrintPreviewWidget

    Hi friends,

    I'm having some difficulties with the QPrintPreviewWidget.
    I'm trying to create some reports, but in different distributions (in special, Fedora 9 and Kubuntu 8.10) preview the contents of the leaves off the page and others do not come to occupy the entire page. Sending a small sample code and images.

    ReportTest.h:
    Qt Code:
    1. #ifndef REPORTTEST_H
    2. #define REPORTTEST_H
    3.  
    4. #include <QPrintPreviewWidget>
    5. #include <QWidget>
    6. #include <QPrinter>
    7. #include <QPainter>
    8. #include <QRect>
    9.  
    10. class ReportTest: public QWidget
    11. {
    12. Q_OBJECT
    13. public:
    14. ReportTest(QWidget *parent = 0);
    15. QPrinter *printer;
    16.  
    17. private:
    18.  
    19. private slots:
    20. void print(QPrinter *printer);
    21.  
    22. protected:
    23. };
    24. #endif
    To copy to clipboard, switch view to plain text mode 

    ReportTest.cpp:
    Qt Code:
    1. #include "ReportTest.h"
    2.  
    3. ReportTest::ReportTest(QWidget *parent)
    4. :QWidget(parent)
    5. {
    6. printer = new QPrinter;
    7. printer->setOutputFormat(QPrinter::NativeFormat);
    8. printer->setOrientation(QPrinter::Portrait);
    9. printer->setPaperSize(QPrinter::A4);
    10. printer->setFullPage(TRUE);
    11.  
    12. QPrintPreviewWidget *printPreview = new QPrintPreviewWidget(printer);
    13.  
    14. connect(printPreview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
    15. printPreview->show();
    16.  
    17. printPreview->fitInView();
    18. }
    19.  
    20. void ReportTest::print(QPrinter *printer)
    21. {
    22. QPainter painter(printer);
    23. painter.setRenderHints(QPainter::Antialiasing |
    24. QPainter::TextAntialiasing |
    25. QPainter::SmoothPixmapTransform, true);
    26.  
    27. QRect rect(QPoint(30, 30), QSize(750, 30));
    28. painter.drawRect(rect);
    29.  
    30. //printer->newPage();
    31. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

Similar Threads

  1. Trouble compiling new Qt on win (mingw)
    By macbeth in forum Installation and Deployment
    Replies: 2
    Last Post: 20th September 2008, 09:28
  2. QT-wince and QHttp::readAll() trouble....
    By AcerExtensa in forum Qt for Embedded and Mobile
    Replies: 6
    Last Post: 12th June 2008, 09:40
  3. Replies: 3
    Last Post: 19th November 2007, 15:31
  4. Trouble placing QLabel on top ofQGLWidget
    By JimDaniel in forum Qt Programming
    Replies: 1
    Last Post: 8th October 2007, 23:48
  5. Replies: 18
    Last Post: 6th February 2007, 14:06

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.