NV4RE
NV4RE

Reputation: 193

QPainter::begin: Paint device returned engine == 0, type: 2

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);
}

log table

Upvotes: 2

Views: 8160

Answers (1)

NV4RE
NV4RE

Reputation: 193

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);

Printing Widgets

Upvotes: 2

Related Questions