I'm trying to print Qtablewidget but it just print a blank page and application output show
QPrinter::metric: Invalid metric command
QPainter::begin: Paint device returned engine == 0, type: 2
QWidget::render: Cannot render with an inactive painter
print function
void MainWindow::on_btPrint_clicked(){
QPrinter printer(QPrinter::HighResolution);
QPrintDialog printer_dialog(&printer, this);
if (printer_dialog.exec() == QDialog::Rejected) return;
QPainter painter(&printer);
ui->table_log->render(&painter);
}
Fixed by set painter.scale
double xscale = printer.pageRect().width()/double(ui->table_log->width());
double yscale = printer.pageRect().height()/double(ui->table_log->height());
double scale = qMin(xscale, yscale);
painter.scale(scale, scale);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.