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
{
Q_OBJECT
public:
QPrintPreviewWidget *printPreview;
private:
Ui::Report ui;
private slots:
void print();
};
#endif
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
To copy to clipboard, switch view to plain text mode
Report.cpp
#include "Report.h"
{
ui.setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
this->showMaximized();
printer
->setOutputFormat
(QPrinter::NativeFormat);
printer
->setOrientation
(QPrinter::Portrait);
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()
{
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();
}
}
#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();
}
}
To copy to clipboard, switch view to plain text mode
Thanks,
Marcelo E. Geyer
Bookmarks