Hi,

I would like to print a table which contains text only. I search through the forum and found this piece of code

Qt Code:
  1. QPainter painter(printer);
  2. const QRect area = printer->pageRect();
  3. const int rows = m_data_model.rowCount();
  4. const int cols = m_data_model.columnCount();
  5.  
  6. // calculate the total width/height table would need without scaling
  7. double totalWidth = 0.0;
  8. for (int c = 0; c < cols; ++c)
  9. {
  10. totalWidth += columnWidth(c);
  11. }
  12. double totalHeight = 0.0;
  13. for (int r = 0; r < rows; ++r)
  14. {
  15. totalHeight += rowHeight(r);
  16. }
  17.  
  18. // paint cells
  19. for (int r = 0; r < rows; ++r)
  20. {
  21. for (int c = 0; c < cols; ++c)
  22. {
  23. QModelIndex idx = m_data_model.index(r, c);
  24. QStyleOptionViewItem option = viewOptions();
  25. option.rect = visualRect(idx);
  26. itemDelegate()->paint(&painter, option, idx);
  27. }
  28. }
To copy to clipboard, switch view to plain text mode 

However, the code does not print the table's vertical and horizontal headers, as well as the grid lines. How can I print a table, with both the headers and the grid lines?

I am using Qt4.4.

Thanks.