2 Attachment(s)
Difference between what a QGraphicsScene shows and what I save
Hi to all,
I'm having trouble saving the image showed in a QGraphicsScene. Here is an application's screenshot (screen-01.jpg) that worth more than thousands words:
http://www.qtcentre.org/asset.php?fi...8&d=1264742723
it's an histogram that shows two values, and the following is the resulting image saved (statistiche.png):
http://www.qtcentre.org/asset.php?fi...8&d=1264742721
it's, incredibly, without the green values.
Ok, I'm going to show you my code to build the histogram and save it:
Code:
// Build the Histogram
void frmStats::setupGrafico()
{
// qDebug() << "frmStats setupGrafico";
if (maxCifraAnno == 0)
{
singolaUnitaIsto = 0;
}
else
{
singolaUnitaIsto = - 1 * (double(maxAltezzaIsto) / double(maxCifraAnno));
}
scene->clear();
// X line
endY - margineY), 0, scene);
ascissa
->setPen
(QPen(Qt
::black,
3, Qt
::SolidLine));
// Y line
scene);
ordinata
->setPen
(QPen(Qt
::black,
3, Qt
::SolidLine));
for (int i = 1; i < 4; i++)
{
// 25%, 50% and 75% lines
int factorY = ((endY - margineY) / 4) * i;
(margineX, factorY, endX - 10, factorY), 0, scene);
livelliY
->setPen
(QPen(Qt
::black,
1, Qt
::DashLine));
int h = int(testoPercentuale->boundingRect().height() / 2);
int w = int(testoPercentuale->boundingRect().width());
testoPercentuale->setPos(margineX - w, factorY - h);
}
font.setPointSize(14);
for (int i = 0; i < 12; i++)
{
/*
Draw the histogram's values per month
*/
60, int(totMese[i] * singolaUnitaIsto)), 0, scene);
isto
->setPen
(QPen(Qt
::black,
1, Qt
::SolidLine));
isto->setBrush(Qt::green);
isto->setOpacity(0.7);
/*
histogram' s text
*/
inEuro
= QString("%L1").
arg(totMese
[i
] ,
12,
'f',
2,
' ');
testoIsto->setFont(font);
testoIsto->setDefaultTextColor(Qt::black);
testoIsto->setHtml(inEuro);
int xSize = int(testoIsto->boundingRect().height());
testoIsto->setPos(margineX + 2 + 30 - int(xSize / 2) + 60 * i,
(endY - margineY - 2));
testoIsto->rotate(-90);
testoIsto->translate(20, 0);
/*
Porto in fronte - di livello - il testo con setZValue.
*/
testoIsto->setZValue(0.1);
/*
Month's text
*/
int h = int(testoMese->boundingRect().height() / 2);
int w = int(testoMese->boundingRect().width() / 2);
testoMese->setPos
(margineX + 30 - w + 60 * i, (endY - (margineY / 2 + h)));
}
}
Code:
// Print the image
void frmStats::creaFileHtml()
{
// qDebug() << "->frmStats creaFileHtml";
painter.
setRenderHint(QPainter::Antialiasing);
scene->render(&painter);
painter.end();
pixmap.
save(QDir::currentPath() + "/statistiche.png");
// qDebug() << QDir::currentPath() + "/statistiche.png";
}
and that's all, please help me!
thanks
1 Attachment(s)
Re: Difference between what a QGraphicsScene shows and what I save
Hi to all,
I've created a little, stand-alone project to test with Qt Creator. Could someone test it?
I need feedback, please!
Thanks.