PDA

View Full Version : QPrinPreview differences between Windows and Linux



giusepped
19th October 2009, 09:45
I use the same code for print preview. But in Windows I get a quite different preview from Linux.
See the attached screenshots.
Why?

Lykurg
19th October 2009, 10:02
Can you show us your code? From the screenshots it seems that you don'T have specified the pagesize and therefor it uses the default pagesizes on the platforms, which could differe.

giusepped
19th October 2009, 12:53
void MainWindow::printPreview(){
QPrinter print(QPrinter::HighResolution);
print.setPaperSize(QPrinter::A4);
print.setPageSize(QPrinter::A4);
QPrintPreviewDialog preview(&print,this);
connect(&preview, SIGNAL(paintRequested(QPrinter *)), SLOT(printPreview(QPrinter*)));
preview.exec();
}
...
void MainWindow::printPreview(QPrinter* p){
printReport(p,0);
}

In printPreview there is a call to a method in a class:



...
m_document->setPageSize(printer->pageRect().size());

...
QString site =" <table bgcolor=\"lightGray\" border=\"0\"><tbody><tr ><td width=\"800\">" + QObject::tr("Sito") +"</td></tr></tbody> </table>";
m_cursor.insertHtml(site);
m_cursor.insertText(QObject::tr("Sito"),boldFormat);
m_cursor.movePosition(QTextCursor::EndOfBlock);

QPainter p;
int pw = printer->pageRect().width();
int ph =printer->pageRect().height();

p.begin(printer);

p.save();
m_document->adjustSize();
QTransform tra;
tra.scale(11,11);
p.setTransform(tra);
...
m_document->drawContents(&p,printer->paperRect());

p.restore();
p.end();

chapu
19th April 2010, 16:54
Hi, I have a different problem with QPrintPreviewDialog on Linux. The initial size of the preview window is too small. How do I set the size of the preview window?

Lykurg
19th April 2010, 16:58
QPrintPreviewDialog is a normal dialog. So just use QWidget::geometry or QWidget::adjustSize().