Hi all,
I've just swiched from Qt 4.2.2 to Qt 4.4.3 anf the code I show below does not work anymore. It prints black lines .. any of you knows why it appens ??
Thank you in advance.
rmagro

Qt Code:
  1. QPrinter printer(QPrinter::HighResolution);
  2. printer.setOrientation(QPrinter::Landscape);
  3.  
  4. QTableWidget *nuovaTableWidget = tableWidget;
  5.  
  6. QPrintDialog dlg(&printer, this);
  7.  
  8. if (dlg.exec() == QDialog::Accepted)
  9. {
  10. // calculate the total width/height table would need without scaling
  11. const int rows = nuovaTableWidget->model()->rowCount();
  12. const int cols = nuovaTableWidget->model()->columnCount();
  13.  
  14. double totalWidth = 0.0;
  15.  
  16. for (int c = 0; c < cols; ++c)
  17. {
  18. totalWidth += nuovaTableWidget->columnWidth(c);
  19. }
  20.  
  21. double totalHeight = 0.0;
  22.  
  23. for (int r = 0; r < rows; ++r)
  24. {
  25. totalHeight += nuovaTableWidget->rowHeight(r);
  26. }
  27.  
  28. double totalHeight1;
  29. int numero_pagina = 1;
  30.  
  31. QPixmap pixmap(totalWidth, nuovaTableWidget->horizontalHeader()->height());
  32. QPixmap pixmap1(totalWidth, totalHeight);
  33.  
  34. QPaintEvent event_1(QRect(0, 0, totalWidth, nuovaTableWidget->horizontalHeader()->height()));
  35. QPaintEvent event_2(QRect(0, 0, totalWidth, totalHeight));
  36.  
  37. QPainter::setRedirected(nuovaTableWidget->horizontalHeader()->viewport(), &pixmap);
  38. QApplication::sendEvent(nuovaTableWidget->horizontalHeader()->viewport(), &event_1);
  39. QPainter::restoreRedirected(nuovaTableWidget->horizontalHeader()->viewport());
  40.  
  41. QPainter::setRedirected(nuovaTableWidget->viewport(), &pixmap1);
  42. QApplication::sendEvent(nuovaTableWidget->viewport(), &event_2);
  43. QPainter::restoreRedirected(nuovaTableWidget->viewport());
  44.  
  45. // print scaled pixmap
  46. QPainter painter(&printer);
  47.  
  48. QDateTime dataDiOggi = QDateTime::currentDateTime();
  49. QString dataDiOggiStringa = dataDiOggi.toString("dd.MM.yyyy hh:mm:ss");
  50.  
  51. painter.scale(4.5,4.5);
  52. painter.drawPixmap(0, 100, totalWidth, nuovaTableWidget->horizontalHeader()->height(), pixmap);
  53. painter.drawPixmap(0, 100+nuovaTableWidget->horizontalHeader()->height(), totalWidth, totalHeight, pixmap1);
  54. }
To copy to clipboard, switch view to plain text mode