我正在尝试打印 Qtablewidget,但它只打印一个空白页并显示应用程序输出
QPrinter::metric: Invalid metric command
QPainter::begin: Paint device returned engine == 0, type: 2
QWidget::render: Cannot render with an inactive painter
打印功能
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);
}
通过设置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);