[Qt-interest] QPrinter bug?
Brad Pepers
brad at linuxcanada.com
Sat Apr 11 01:15:59 CEST 2009
I'm using Qt 4.5.0 on a Mac and finding an oddity in printing. If I
set the paper size ahead of time, my printing is messed up. Here is
the example code:
QPrinter printer(QPrinter::HighResolution);
printer.setFullPage(true);
printer.setMinMax(1, 1);
// ** this line causes the problems **
printer.setPaperSize(QSizeF(8.5, 11), QPrinter::Inch);
if (!printer.setup(NULL)) return;
QPainter p;
p.begin(&printer);
p.setWindow(0, 0, 5100, 6600);
QColor color("black");
p.fillRect(600, 600, 600, 600, color);
p.fillRect(3900, 600, 600, 600, color);
p.fillRect(600, 5400, 600, 600, color);
p.fillRect(3900, 5400, 600, 600, color);
p.end();
return;
I would think that by setting the window of the painter to 5100x6600 I
should always get 4 boxes in the corners of the printout back 1 inch
that are 1x1 inches. If I don't call the setPaperSize, then it
works. With the call to setPaperSize, I get a couple tiny little
boxes in the bottom left corner of the page.
One thing I've noticed in testing is that if I don't set the paper
size, the window and viewport default to 5100x6600 so that is likely
why they work. With the setPaperSize call, the window and viewport
default to 589x769 but then I set the window to 5100x6600 so it should
still work right?
While I'm at it, why the 589x769? That seems to be the size in points
(72 dpi) with some margins but I called the setFullPage(true) so why
the margins? I would perhaps understand it being 612x792 but not
these values. Perhaps there is some fixed order the methods need to
be called in like using setPageSize after setFullPage?
--
Brad
More information about the Qt-interest-old
mailing list