I am using Qt version 4.8.4 on Window 7. I don’t have conditions to test this issue on another platform such as Mac, Linux… and I use the following code to preview content

Qt Code:
  1. void DemoClass::on_btnOK_clicked()
  2. {
  3. QPrinter printer;
  4. printer.setResolution(QPrinter::HighResolution);
  5. printer.setPaperSize(QPrinter::A4);
  6. printer.setOrientation(QPrinter::Portrait);
  7. printer.setFullPage(true);
  8.  
  9. QPrintPreviewDialog *printPreview = new QPrintPreviewDialog(&printer);
  10. connect(printPreview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
  11.  
  12. printPreview->setWindowTitle("Preview Dialog");
  13. Qt::WindowFlags flags(Qt::WindowTitleHint);
  14. printPreview->setWindowFlags(flags);
  15. printPreview->exec();
  16. }
  17.  
  18. void DemoClass::print(QPrinter *printer)
  19. {
  20. QPainter painter(printer);
  21. painter.setRenderHints(QPainter::Antialiasing |
  22. QPainter::TextAntialiasing |
  23. QPainter::SmoothPixmapTransform, true);
  24.  
  25. painter.drawText(100, 100, "Hello World! 123");
  26. }
To copy to clipboard, switch view to plain text mode 

On pushing the OK button, this dialog appears:

09-09-2013 18-03-43.png

As you see, the page is blank. The page doesn’t contain any content. Then I click the page setup button on the preview dialog and this appears:

09-09-2013 18-04-23.png

…without changing anything, I click OK and then the preview becomes correct:

09-09-2013 18-05-18.png

I really don’t understand what the reason is. How can I show the content correctly without changing page setup?

Do you have any solutions?