what unit is used in QTextDocument::setPageSize() method?
My program involve printing to a roll script which is just 8 cm width. I have set the paper size of the QPrinter accordingly. The content is rendered from a QTextDocument object. The output was cropped on the right side. Hence I would like to set the page size on the QTextDocument in order to render the content correctly. The problem is, what unit is used in the QTextDocument::setPageSize method?
Here is my code snip.
Code:
lrPrinter.
setPageMargins(0.0,
0.0,
0.0,
0.0,
QPrinter::Millimeter);
if (lpDlg
->exec
() != QDialog::Accepted) {
return;
}
lpDocument->print(&lrPrinter);
development environment:
Qt 4.4.0.
MSVC 8.0 SP1 with Qt Visual Studio Integration 1.4.0.
Win XP SP3.
Re: what unit is used in QTextDocument::setPageSize() method?
I think you meant:
If you look at the mergins after this:
Code:
lrPrinter.
setPageMargins(0.0,
0.0,
0.0,
0.0,
QPrinter::Millimeter);
you might find they are not zero and shifting your output to the right. Something similar to this is happening to me on Windows (http://www.qtcentre.org/forum/f-qt-p...ffs-23771.html), where even
does not seem to help.
Does it look correct if you output to PDF?
Re: what unit is used in QTextDocument::setPageSize() method?
The unit for QTextDocument is point (pt).
Code:
const qreal PT_MM = 25.4/72.0;
document.setDocumentMargin(20.0/PT_MM); // sets margin to 20mm
It also works with html images:
Code:
document.setHtml("<img src=\"anyimg.jpg\" width = 200 />); // creates an image 200pt = 200*PT_MM millimeters wide
To set a PageSize use:
Code:
document.setPageSize(size);