I'm missing something:
In the following code, I must display a QMessageBox to get a correct QPixmap (with a chart in it).
Do you know what's the problem?

Thanks.
Regards,
Oscar

Qt Code:
  1. QPixmap MyExport::drawPie(int size, QList<int> valueList, QList<QString> colorList) {
  2.  
  3. QPixmap qPixmap(size,size);
  4. QPainter *myQPainter = new QPainter(&qPixmap);
  5.  
  6. myQPainter->setBrush(QBrush(QColor(245,245,245)));
  7. myQPainter->drawRect(0,0,size,size);
  8.  
  9. double startAngle = 0.0;
  10. double totalValue; foreach(int value, valueList) totalValue += value;
  11.  
  12. for (int i=0; i<valueList.size(); i++) {
  13. if (valueList[i] > 0.0) {
  14. double angle = 360*valueList[i]/totalValue;
  15. QColor color = QColor(colorList[i]);
  16. myQPainter->setBrush(QBrush(color));
  17. myQPainter->drawPie(0, 0, size-2, size-2, int(startAngle*16), int(angle*16));
  18. startAngle += angle;
  19. }
  20. }
  21. delete myQPainter;
  22.  
  23. QMessageBox::information(NULL, QString::fromUtf8("Warn"),
  24. QString::fromUtf8("This messagebox must be called to make this example function"),
  25. QString::fromUtf8("Quitter"));
  26. return qPixmap;
  27. }
To copy to clipboard, switch view to plain text mode