Hi all,
the code that follows stop working correctly when I upgrade from Qt4.2.2 to Qt4.4.3..
The only think printed is a bold black line..

Any clue about how I can solve?

Thx very mutch

Qt Code:
  1. QPrinter printer(QPrinter::HighResolution);
  2. printer.setOrientation(QPrinter::Landscape);
  3.  
  4. QTableWidget *newTableWidget = 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 = newTableWidget ->model()->rowCount();
  12. const int cols = newTableWidget ->model()->columnCount();
  13.  
  14. double totalWidth = 0.0;
  15.  
  16. for (int c = 0; c < cols; ++c)
  17. {
  18. totalWidth += newTableWidget ->columnWidth(c);
  19. }
  20.  
  21. double totalHeight = 0.0;
  22.  
  23. for (int r = 0; r < rows; ++r)
  24. {
  25. totalHeight += newTableWidget ->rowHeight(r);
  26. }
  27.  
  28. double totalHeight1;
  29. int num_page = 1;
  30.  
  31. while (totalHeight > 900)
  32. {
  33. totalHeight1 = 900;
  34.  
  35. // redirect table's painting on a pixmap
  36. QPixmap pixmap(totalWidth, newTableWidget->horizontalHeader()->height());
  37. QPixmap pixmap1(totalWidth, totalHeight1);
  38.  
  39. QPaintEvent event(QRect(0, 0, totalWidth, newTableWidget->horizontalHeader()->height()));
  40. QPaintEvent event1(QRect(0, 0, totalWidth, totalHeight1));
  41.  
  42. QPainter::setRedirected(newTableWidget->horizontalHeader()->viewport(), &pixmap);
  43. QApplication::sendEvent(newTableWidget->horizontalHeader()->viewport(), &event);
  44. QPainter::restoreRedirected(newTableWidget->horizontalHeader()->viewport());
  45.  
  46. QPainter::setRedirected(newTableWidget->viewport(), &pixmap1);
  47. QApplication::sendEvent(newTableWidget->viewport(), &event1);
  48. QPainter::restoreRedirected(newTableWidget->viewport());
  49.  
  50. // print scaled pixmap
  51. QPainter painter(&printer);
  52.  
  53. QDateTime dataDiOggi = QDateTime::currentDateTime();
  54. QString dataDiOggiStringa = dataDiOggi.toString("dd.MM.yyyy hh:mm:ss");
  55.  
  56. painter.drawText(0, 250, tr("Qt 4.3.3 - Date: %1 -") .arg(dataDiOggiStringa));
  57. painter.drawText(0, 150, tr("Page %1") .arg(num_page));
  58.  
  59. painter.scale(4.5,4.5);
  60. painter.drawPixmap(0, 100, totalWidth, newTableWidget->horizontalHeader()->height(), pixmap);
  61. painter.drawPixmap(0, 100+newTableWidget->horizontalHeader()->height(), totalWidth, totalHeight1, pixmap1);
  62.  
  63. totalHeight = totalHeight - totalHeight1;
  64. printer.newPage();
  65. numero_pagina = numero_pagina + 1;
  66. }
  67.  
  68. QPixmap pixmap(totalWidth, newTableWidget->horizontalHeader()->height());
  69. QPixmap pixmap1(totalWidth, totalHeight);
  70.  
  71. QPaintEvent event(QRect(0, 0, totalWidth, newTableWidget->horizontalHeader()->height()));
  72. QPaintEvent event1(QRect(0, 0, totalWidth, totalHeight));
  73.  
  74. QPainter::setRedirected(newTableWidget->horizontalHeader()->viewport(), &pixmap);
  75. QApplication::sendEvent(newTableWidget->horizontalHeader()->viewport(), &event);
  76. QPainter::restoreRedirected(newTableWidget->horizontalHeader()->viewport());
  77.  
  78. QPainter::setRedirected(newTableWidget->viewport(), &pixmap1);
  79. QApplication::sendEvent(newTableWidget->viewport(), &event1);
  80. QPainter::restoreRedirected(newTableWidget->viewport());
  81.  
  82. // print scaled pixmap
  83. QPainter painter(&printer);
  84.  
  85. QDateTime dataDiOggi = QDateTime::currentDateTime();
  86. QString dataDiOggiStringa = dataDiOggi.toString("dd.MM.yyyy hh:mm:ss");
  87.  
  88. painter.drawText(0, 250, tr("Qt 4.3.3 - Date: %1 - ") .arg(dataDiOggiStringa));
  89. painter.drawText(0, 150, tr("Page %1") .arg(num_page));
  90.  
  91. painter.scale(4.5,4.5);
  92. painter.drawPixmap(0, 100, totalWidth, newTableWidget->horizontalHeader()->height(), pixmap);
  93. painter.drawPixmap(0, 100+newTableWidget->horizontalHeader()->height(), totalWidth, totalHeight, pixmap1);
  94. }
To copy to clipboard, switch view to plain text mode