Thank you very much! That has worked. But now I encountered another problem.
When I'm calling QPrintPreviewDialog, there is two pages, thow I rendered only my central widget. So I have one page with my central widget and another page empty.
Also the Image is printed correctly on the page only if I open the app in fullscreen. If I call my app and it is not stretched to full screen than I see onle part of it on the first page.
I provide the code of my print preview SLOT and connects.
connect(prev_dialog,
SIGNAL(paintRequested
(QPrinter*)),
this,
SLOT(print_preview
()));
connect(ui->actionPrint_Preview, SIGNAL(triggered(bool)), this, SLOT(preview_called()));
//////////////////////////////////////////////////////////////////////////////////////////
void MainWindow::print_preview(void)
{
painter.setWindow(this->geometry());
this->render(&painter);
printer.newPage();
/*if (prev_dialog->exec() == QDialog::Accepted)
{
}*/
}
void MainWindow::preview_called(void)
{
prev_dialog->exec();
}
connect(prev_dialog, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print_preview()));
connect(ui->actionPrint_Preview, SIGNAL(triggered(bool)), this, SLOT(preview_called()));
//////////////////////////////////////////////////////////////////////////////////////////
void MainWindow::print_preview(void)
{
QPainter painter(&printer);
painter.setWindow(this->geometry());
this->render(&painter);
printer.newPage();
/*if (prev_dialog->exec() == QDialog::Accepted)
{
}*/
}
void MainWindow::preview_called(void)
{
prev_dialog->exec();
}
To copy to clipboard, switch view to plain text mode
Thank you again for helping me to deal with this.
Bookmarks