void Widget::on_pushButton_2_clicked(){ printFile();}void Widget::printFile(){ QPrinter printer; QPrintDialog *dialog = new QPrintDialog(&printer); dialog->setWindowTitle(tr("Print Document")); if (dialog->exec() != QDialog::Accepted) return; QPainter painter; painter.begin(&printer); double xscale = printer.pageRect().width()/double(ui->tbl->width()); double yscale = printer.pageRect().height()/double(ui->tbl->height()); double scale = qMin(xscale, yscale); painter.translate(printer.paperRect().x() + printer.pageRect().width()/2, printer.paperRect().y() + printer.pageRect().height()/2); painter.scale(scale, scale); painter.translate(-width()/2, -height()/2); ui->tbl->render(&painter);}