Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. PieChat : addPie function removed other pies!

PieChat : addPie function removed other pies!

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kamhagh
    wrote on last edited by
    #1

    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 :)

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      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.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kamhagh
        wrote on last edited by
        #3

        [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

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          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!

          Greetz, Jeroen

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kamhagh
            wrote on last edited by
            #5

            [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:)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved