I ran into similar issue lately. It turned out that QTextDocument will allways assume (logical) screen resolution when painting, and that is probably different between windows and linux. On windows (where I'm working) the logical screen resolution is 96 DPI.
In my case everything was fine when printing in default QPrinter::ScreenResolution mode, but everything was far too small when printing with QPrinter::HighResolution.
My workaround was to scale the QPainter so QTextDocument could paint believing that the resolution is = screen resolution, and QPainter would "fix" it by its transformation.
Here a snippet of code:
int screenResolution = Bps::screenResolution();
qreal oldWidth = prv_->mDocument.textWidth();
if (prv_->mResolution>0 && prv_->mResolution != screenResolution) {
qreal f = prv_->mResolution / screenResolution;
aPainter->scale(f, f);
prv_->mDocument.setTextWidth(oldWidth / f);
} // if
prv_->mDocument.drawContents(aPainter);
prv_->mDocument.setTextWidth(oldWidth);
int screenResolution = Bps::screenResolution();
qreal oldWidth = prv_->mDocument.textWidth();
if (prv_->mResolution>0 && prv_->mResolution != screenResolution) {
qreal f = prv_->mResolution / screenResolution;
aPainter->scale(f, f);
prv_->mDocument.setTextWidth(oldWidth / f);
} // if
prv_->mDocument.drawContents(aPainter);
prv_->mDocument.setTextWidth(oldWidth);
To copy to clipboard, switch view to plain text mode
Bookmarks