PDA

View Full Version : QPrintPreviewDialog printing just one page of multiple pages.



kea_
22nd February 2011, 07:58
Hello together,

I like to print one page of multiple pages. But the printer allways prints all pages.
What I'm doing wrong?

Please have a look at the source.

void CPrintWorkout::print(){
QPrinter printer(QPrinter::ScreenResolution);
printer.setPageSize(QPrinter::A4);
printer.setOrientation(QPrinter::Landscape);

QPrintPreviewDialog preview(&printer);
connect(&preview, SIGNAL(paintRequested(QPrinter*)), SLOT(print(QPrinter*)));
preview.exec();
}


// ** SLOTS **

void CPrintWorkout::print(QPrinter *printer){
printer->setPageOrder(QPrinter::FirstPageFirst);

QPainter painter;
painter.begin(printer);

QTextDocument doc;
doc.setTextWidth(printer->pageRect().width());

for(int i = 1; i <= 3; i++){
doc.setHtml(QString::number(i) + ". Page");
doc.drawContents(&painter);

if(i < 3) printer->newPage();
}

painter.end();
}


Thank you very much.
kea_

aliks-os
15th April 2014, 07:16
Hi
I have the same problem. Did you fix it?

ChrisW67
16th April 2014, 04:26
If you do not want all the pages in the output then do not render all the pages in the slot you attach to paintRequested(). If the user has opted to print only a range of pages, for example, then the QPrinter object will return that range through QPrinter::printRange(), QPrinter::fromPage() and QPrinter::toPage(). Only render the requested pages.