Hi Qt Community,

I'm using the following code to print out a QTableWidget,
but I only get the the contents inside the table and not the horizontalHeader..

Qt Code:
  1. QPrinter printer(QPrinter::HighResolution);
  2. printer.setOrientation(QPrinter::Landscape);
  3.  
  4. QPrintDialog dlg(&printer, this);
  5.  
  6. if (dlg.exec() == QDialog::Accepted)
  7. {
  8. // calculate the total width/height table would need without scaling
  9. const int rows = tableWidget->model()->rowCount();
  10. const int cols = tableWidget->model()->columnCount();
  11. double totalWidth = 0.0;
  12.  
  13. for (int c = 0; c < cols; ++c)
  14. {
  15. totalWidth += tableWidget->columnWidth(c);
  16. }
  17.  
  18. double totalHeight = 0.0;
  19.  
  20. for (int r = 0; r < rows; ++r)
  21. {
  22. totalHeight += tableWidget->rowHeight(r);
  23. }
  24.  
  25. // redirect table's painting on a pixmap
  26. QPixmap pixmap(totalWidth, totalHeight);
  27. QPainter::setRedirected(tableWidget->viewport(), &pixmap);
  28. QPaintEvent event(QRect(0, 0, totalWidth, totalHeight));
  29. QApplication::sendEvent(tableWidget->viewport(), &event);
  30. QPainter::restoreRedirected(tableWidget->viewport());
  31.  
  32. // print scaled pixmap
  33. QPainter painter(&printer);
  34. painter.scale(4,4);
  35. //painter.drawPixmap(printer.pageRect(), pixmap, pixmap.rect());
  36. painter.drawPixmap(printer.pageRect().topLeft(), pixmap, pixmap.rect());
  37. }
To copy to clipboard, switch view to plain text mode 

What to add to get it?

Thanks you very much for your help,

Roby