Hi i am using qtablewidget in my project..it has 10 columns & 5000 rows...i want to print the whole tablewidget... When i use the below code i get a empty pdf for 5000 rows...if i use it for less rows like 50 ,it prints only the visible area of the table widget...
How to solve this issue?
Is there any way do display a widget page wise , say 100 rows per page and take printout of 100 rows and print another 100 from 2nd page?
kindly help
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 = ui->Packet_Info->model()->rowCount();
  10. const int cols = ui->Packet_Info->model()->columnCount();
  11.  
  12. double totalWidth = 0.0;
  13.  
  14. for (int c = 0; c < cols; ++c)
  15. {
  16. totalWidth += ui->Packet_Info->columnWidth(c);
  17. }
  18.  
  19. double totalHeight = ui->Packet_Info->horizontalHeader()->height();
  20.  
  21. for (int r = 0; r < rows; ++r)
  22. {
  23. totalHeight += ui->Packet_Info->rowHeight(r);
  24. }
  25.  
  26.  
  27. // redirect table's painting on a pixmap
  28. QPixmap pixmap(totalWidth, totalHeight );
  29.  
  30. QPainter::setRedirected(ui->Packet_Info->horizontalHeader()->viewport(), &pixmap);
  31. QPainter::setRedirected(ui->Packet_Info->viewport(), &pixmap);
  32.  
  33. QPaintEvent event(QRect(0, 0, totalWidth, totalHeight ));
  34.  
  35. QApplication::sendEvent(ui->Packet_Info->horizontalHeader()->viewport(), &event);
  36. QApplication::sendEvent(ui->Packet_Info->viewport(), &event);
  37.  
  38. QPainter::restoreRedirected(ui->Packet_Info->horizontalHeader()->viewport());
  39. QPainter::restoreRedirected(ui->Packet_Info->viewport());
  40.  
  41.  
  42.  
  43. // print scaled pixmap
  44. QPainter painter(&printer);
  45. painter.scale(4,4);
  46. //painter.drawPixmap(printer.pageRect(), pixmap, pixmap.rect());
  47. painter.drawPixmap(printer.pageRect().topLeft(), pixmap, pixmap.rect());
  48.  
  49. }
To copy to clipboard, switch view to plain text mode