PDA

View Full Version : Trouble to print with QPrintPreviewWidget



estanisgeyer
23rd December 2008, 10:39
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


class Report: public QMainWindow
{
Q_OBJECT
public:
Report(QWidget *parent = 0, QWidget *widgetReport = 0);
QPrinter *printer;
QPrintPreviewWidget *printPreview;

private:
Ui::Report ui;

private slots:
void print();
};
#endif


Report.cpp


#include "Report.h"
Report::Report(QWidget *parent, QWidget *widgetReport)
:QMainWindow(parent)
{
ui.setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
this->showMaximized();

printer = new QPrinter(QPrinter::HighResolution);
printer->setOutputFormat(QPrinter::NativeFormat);
printer->setOrientation(QPrinter::Portrait);
printer->setPaperSize(QPrinter::A4);
printer->setFullPage(true);

printPreview = new QPrintPreviewWidget(printer, this);
ui.gridLayout1->addWidget(printPreview);

connect(ui.ActPrint, SIGNAL(triggered()), this, SLOT(print()));
connect(printPreview, SIGNAL(paintRequested(QPrinter*)), widgetReport, SLOT(Print(QPrinter*)));

printPreview->fitInView();
printPreview->show();
}

void Report::print()
{
QPrintDialog printDialog(printer, printPreview);
printDialog.setMinMax(1, printPreview->numPages());
if (printDialog.exec() == QDialog::Accepted)
{
qDebug() << printPreview->numPages(); // OK, its return 3 pages, but print all if range is one or two.
printPreview->print();
}
}


Thanks,

Marcelo E. Geyer

estanisgeyer
23rd December 2008, 16:23
It's possible to a bug? Or write my class in a way that these controls will not work? Someone has worked with QPrintPreviewWidget?

estanisgeyer
16th January 2009, 18:10
Hi guys, Anybody to help?

seneca
16th January 2009, 23:11
You widgetReport::Print method should read out the the print range and paint accordingly.

hardi
28th May 2009, 04:46
I've got the same problem here. I use pyqt.

Do you have solution already?

Moshiach
24th December 2009, 06:14
I've got a similar problem... Qt is too raw to use it in serious projects :mad:
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.