PDA

View Full Version : QPixmap and printer resolution



wojtek
5th June 2007, 12:15
I want to print a pixmap with high resolution. Unfortunately, when i make QPrinter p(QPrinter::highResolution) or (QPrinter::printerResolution) the pixmap is too small on the paper. Has someone a idea?

My code:

QPrinter p;

QPrintDialog qp (&p, this);
if (qp.exec() == QDialog::Accepted)
{
qDebug () << "printerDialog";
QRect rect (0, 0, 288, 180);
QPixmap qpm = QPixmap::grabWidget(cardWidget, rect);

QPainter painter;
qpm.scaled(p.pageRect().width(), p.pageRect().height(), Qt::KeepAspectRatio);
painter.begin (&p);
painter.drawPixmap (0, 0, qpm);
painter.end();
}

Thanks a lot.

marcel
5th June 2007, 17:48
Override the resolution with QPrinter::setResolution( int dpi ).
You can use 720 dpi, and should result in a good picture quality.

Also, be careful when scaling the pixmaps, because the process is not lossless.

Regards

oscar
31st December 2008, 10:21
It's too late, but just to notice, you should use:

qmp = qpm.scaled(p.pageRect().width(), p.pageRect().height(), Qt::KeepAspectRatio);

instead of:

qpm.scaled(p.pageRect().width(), p.pageRect().height(), Qt::KeepAspectRatio);

Otherwise your qpixmap won't be rescaled!

Regards,
Oscar