Assuming I have a QTreeWidget like that
I tried this code to Print/Export this QTreeWidget to a file (The name of this QTreeWidget is trvListVehicle)
QPrinter printer(QPrinter::HighResolution);
QPainter painter;
painter.begin(&printer);
double xscale = printer.pageRect().width() / double(ui->trvListVehicle->width());
double yscale = printer.pageRect().height() / double(ui->trvListVehicle->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->trvListVehicle->render(&painter);
The program shows Print dialog for me to choose printer machine. After printing completely, I got a blank page. The page didn’t contain any content.
Could you help me?
Thanks!