oscar
7th November 2008, 22:42
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
QPixmap MyExport::drawPie(int size, QList<int> valueList, QList<QString> colorList) {
QPixmap qPixmap(size,size);
QPainter *myQPainter = new QPainter(&qPixmap);
myQPainter->setBrush(QBrush(QColor(245,245,245)));
myQPainter->drawRect(0,0,size,size);
double startAngle = 0.0;
double totalValue; foreach(int value, valueList) totalValue += value;
for (int i=0; i<valueList.size(); i++) {
if (valueList[i] > 0.0) {
double angle = 360*valueList[i]/totalValue;
QColor color = QColor(colorList[i]);
myQPainter->setBrush(QBrush(color));
myQPainter->drawPie(0, 0, size-2, size-2, int(startAngle*16), int(angle*16));
startAngle += angle;
}
}
delete myQPainter;
QMessageBox::information(NULL, QString::fromUtf8("Warn"),
QString::fromUtf8("This messagebox must be called to make this example function"),
QString::fromUtf8("Quitter"));
return qPixmap;
}
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
QPixmap MyExport::drawPie(int size, QList<int> valueList, QList<QString> colorList) {
QPixmap qPixmap(size,size);
QPainter *myQPainter = new QPainter(&qPixmap);
myQPainter->setBrush(QBrush(QColor(245,245,245)));
myQPainter->drawRect(0,0,size,size);
double startAngle = 0.0;
double totalValue; foreach(int value, valueList) totalValue += value;
for (int i=0; i<valueList.size(); i++) {
if (valueList[i] > 0.0) {
double angle = 360*valueList[i]/totalValue;
QColor color = QColor(colorList[i]);
myQPainter->setBrush(QBrush(color));
myQPainter->drawPie(0, 0, size-2, size-2, int(startAngle*16), int(angle*16));
startAngle += angle;
}
}
delete myQPainter;
QMessageBox::information(NULL, QString::fromUtf8("Warn"),
QString::fromUtf8("This messagebox must be called to make this example function"),
QString::fromUtf8("Quitter"));
return qPixmap;
}