PieChat : addPie function removed other pies!
-
hi, first, i was making a custom widget, but for now im just making the code, then i make it a addable widget !
my issue is when i call AddPie(int percent,QColor color) :@void Donut::AddPie(int per,QColor Color)
{
Angle = (per*360)/100;
Piecolor = Color;
notfirsttime = true;
repaint();
}
@and when i call repaint:
@void Donut::paintEvent(QPaintEvent *e)
{
Q_UNUSED(e);QPainter painter(this); painter.setPen(QPen(Qt::black, 2.0)); painter.setRenderHint(QPainter::Antialiasing); int h = height()/2; int w = width()/2; painter.translate(QPoint(w,h)); painter.drawEllipse(-80, -80, 160, 160); if(notfirsttime){ painter.setBrush(QBrush(Piecolor)); painter.drawPie(-80, -80, 160, 160, LastAngle*16, Angle*16); LastAngle = Angle; }
}@
it makes a new painter each time, which makes it delete one one and that makes it delete old pie pieces !
so i thought of some arrays that hold all the pies, and each time it repaints all the pie pieces , but the problem is : i have no idea how many pies the user gonna add ! 10000 or 2 ! (im planning to add float percent too !
so anyway to prevent painting new pies remove old ones? like declaring the painter in header? (which didnt work :( )
i guess there most be a way to declare painter only once ! also think taht used memory and cpu (it wastes memory and cpu usage)so please tell me what to do im really Hungry :D i want some pies :)
-
Hi,
I would recommend reading the PieChart example. It illustrates the Painter for data coming from a model. If you don't need that fancy Model/View stuff, you might want to place a QList in your class that holds all the pies. When a new pie is inserted you add it to the list and recalculate all the percentages of the individual pies. (Might even place the pie in a seperate pie class to add the functions to do so).
Then in your painter it is just from the Qlist to the Widget conversion needed. -
[quote author="Jeroentje@home" date="1403514786"]Hi,
I would recommend reading the PieChart example. It illustrates the Painter for data coming from a model. If you don't need that fancy Model/View stuff, you might want to place a QList in your class that holds all the pies. When a new pie is inserted you add it to the list and recalculate all the percentages of the individual pies. (Might even place the pie in a seperate pie class to add the functions to do so).
Then in your painter it is just from the Qlist to the Widget conversion needed.
[/quote]thanks so much:) i first try the QList widget,i tough of class, but as i said i dont know how pies user gonna enter, like i will have to class pie; pie pie[num] , but i dont have nums !unless i ask it from user !
i now see what i have to do, thanks so much, (using the QList only :D) thanks so much, sorry im newbie!
i made a QList container of Class Pie , seeing why i can't append(new Pie(percent,Color)); searching... if i had problem i post here!
trying too add text for each pie :S
-
You're welcome.
Being a newbie is not terrible ;-) Like Gibbs says: Don't say sorry, it's a sign of weakness ;-) We all have to start somewhere.
Good luck and if you need help, just let us know! -
[quote author="Jeroentje@home" date="1403521684"]You're welcome.
Being a newbie is not terrible ;-) Like Gibbs says: Don't say sorry, it's a sign of weakness ;-) We all have to start somewhere.
Good luck and if you need help, just let us know![/quote]ok thanks:)