[Solved] QPrintPreviewDialog the content doesn't show
-
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:
!http://i249.photobucket.com/albums/gg220/HienBoo/09-09-201318-03-43.png(The content doesn't show)!
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:
!http://i249.photobucket.com/albums/gg220/HienBoo/09-09-201318-04-23.png(Click page setup button)!
...without changing anything, I click OK and then the preview becomes correct:
!http://i249.photobucket.com/albums/gg220/HienBoo/09-09-201318-05-18.png(The content is correct)!
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?
-
hmm...you might have found a bug in Qt.
What is the Qt version you are using? And which OS?
Can you reproduce the issue on another platform? -
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...
I also think that is a bug in Qt.
[quote author="raven-worx" date="1378731894"]hmm...you might have found a bug in Qt.
What is the Qt version you are using? And which OS?
Can you reproduce the issue on another platform?[/quote] -
Hi all,
Finally I have solved my issue. I have just removed the line
@printer.setResolution(QPrinter::HighResolution);@
-
ok i have overread that line in your first post.
You are misusing the setResolution method! It "accepts":http://qt-project.org/doc/qt-4.8/qprinter.html#setResolution an int value specifying the dpi resolution and not a QPrinter::PrinterMode enum value.
The enum value you passed has an value of 2 dpi then... -
Thanks for your clearly explanation! It helps me understand more about setResolution functionality.