LeeMinh
10th September 2013, 03:49
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
void DemoClass::on_btnOK_clicked()
{
QPrinter printer;
printer.setResolution(QPrinter::HighResolution);
printer.setPaperSize(QPrinter::A4);
printer.setOrientation(QPrinter::Portrait);
printer.setFullPage(true);
QPrintPreviewDialog *printPreview = new QPrintPreviewDialog(&printer);
connect(printPreview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
printPreview->setWindowTitle("Preview Dialog");
Qt::WindowFlags flags(Qt::WindowTitleHint);
printPreview->setWindowFlags(flags);
printPreview->exec();
}
void DemoClass::print(QPrinter *printer)
{
QPainter painter(printer);
painter.setRenderHints(QPainter::Antialiasing |
QPainter::TextAntialiasing |
QPainter::SmoothPixmapTransform, true);
painter.drawText(100, 100, "Hello World! 123");
}
On pushing the OK button, this dialog appears:
9550
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:
9551
…without changing anything, I click OK and then the preview becomes correct:
9552
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?
void DemoClass::on_btnOK_clicked()
{
QPrinter printer;
printer.setResolution(QPrinter::HighResolution);
printer.setPaperSize(QPrinter::A4);
printer.setOrientation(QPrinter::Portrait);
printer.setFullPage(true);
QPrintPreviewDialog *printPreview = new QPrintPreviewDialog(&printer);
connect(printPreview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
printPreview->setWindowTitle("Preview Dialog");
Qt::WindowFlags flags(Qt::WindowTitleHint);
printPreview->setWindowFlags(flags);
printPreview->exec();
}
void DemoClass::print(QPrinter *printer)
{
QPainter painter(printer);
painter.setRenderHints(QPainter::Antialiasing |
QPainter::TextAntialiasing |
QPainter::SmoothPixmapTransform, true);
painter.drawText(100, 100, "Hello World! 123");
}
On pushing the OK button, this dialog appears:
9550
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:
9551
…without changing anything, I click OK and then the preview becomes correct:
9552
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?