I am really new to C++ and QT. I want to print a mainwindow.ui form with printer. For that I have a code like this:
void MainWindow::on_Button_printer_clicked()
{
ui->Button_printer->setVisible(0);
QPrinter printer(QPrinter::ScreenResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("TestReport.pdf");
printer.setPageMargins(12, 16, 12, 20, QPrinter::Millimeter);
printer.setFullPage(false);
QPainter painter(&printer);
// double xscale = ;
// double yscale = ;
// double scale = qMin(xscale, yscale);
painter.translate(printer.paperRect().center());
// painter.scale(scale, scale);
// painter.translate(-w.width()/ 2, -w.height()/ 2);
//ui->centralwidget->render(&painter);
this->render(&painter);
}
However, I do not know what to render current mainwindow form.. I created it via forms. So I think this. render should have worked but it did not. I also tried :
ui->centralwidget->render(&painter);
That did not work too. How can I render the MainWindow form and put instead of "this" in:
this->render(&painter);