title: Creating a QSector Class (using Qt and QPaint)
body: <p>I have created a class name QSector to draw a sector like the following :
  <a href="http://www.philadelphia-reflections.com/images/GDP_Composition_By_Sector_Graph.jpg" rel="nofollow">http://www.philadelphia-reflections.com/images/GDP_Composition_By_Sector_Graph.jpg</a></p>
  
  <p>QValue is a class with 2 attributes Label (String) and Value (double)
  the QSector class is composed of 4 attributes and is inherited from QWidget</p>
  
  <ul>
  <li>QPainter (to draw things)</li>
  <li>QRect (size and position)</li>
  <li>QVector (store all the data of the sector, values and labels)</li>
  <li>Double total (compute the total of QValue's Values (to compute percentage later))</li>
  </ul>
  
  <p>here is the code :: </p>
  
  <pre><code>// &lt;c++&gt;
  class QValue
  {
  public:
      QValue(QString a = "", double b = 0): f_label(a), f_value(b) {}
  
      double value()  {   return f_value; }
      QString label() {   return f_label; }
  
      void setValue(double a)  {  f_value = a;    }
      void setLabel(QString a) {  f_label = a;    }
  
      void set(QString a, double b)   {   f_label = a;    f_value = b;    }
  
  private:
      QString f_label;
      double  f_value;
  };
  
  class QSector : public QWidget
  {
      Q_OBJECT
  
  public:
      QSector(int width, int height, QWidget *parent = 0)
      : QWidget(parent), f_total(0)
      {
          f_rect = new QRect(1, 1, width - 3 , height - 3);
          this-&gt;resize(width, height);
          f_paint = new QPainter;
      }
  
      void paintEvent(QPaintEvent* event = 0)
      {
          QBrush brush;
  
          brush.setColor(QColor(25, 25, 255));
          brush.setStyle(Qt::SolidPattern);
  
          int startAngle  = 0;
          int spanAngle   = 0;
  
          f_paint-&gt;begin(this);
  
          for (int i = 0; i &lt; f_data.size(); i++)
          {
              int c = ( i * 150) % 255;
              brush.setColor(QColor(c, 25, 255));
              f_paint-&gt;setBrush(brush);
      // 5760 = 360 * 16 = 100%;  total = 100% =&gt; Value * 5760 / total = span angle
              spanAngle = (5760 * f_data[i].value()) / f_total;
  
              f_paint-&gt;drawPie(*f_rect, startAngle, spanAngle);
  
              startAngle = spanAngle;
          }
  
          f_paint-&gt;end();
      }
  
      void add(QString Label, double Value)
      {
          f_data.push_back(QValue(Label, Value));
          f_total = f_total + Value;
  
          update();   //   =&gt; paintEvent();
      }
  
      void add(QValue a)
      {
          f_data.push_back(a);
          f_total = f_total + a.value();
  
          update();   //   =&gt; paintEvent();
      }
  
  signals:
  
  public slots:
  
  private:
      QPainter *f_paint;
      QRect    *f_rect;
  
      QVector&lt;QValue&gt;  f_data;
      double  f_total;
  };
  </code></pre>
  
  <p>Everything Compile.</p>
  
  <p>the problem comes when I do ::</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      QApplication app(argc, argv);
  
      int w = 300;
      int h = 300;
  
      QSector test(w, h);
  
      for (int i = 0, n  = 10; i &lt; n; i++)
          test.add("", 10);
  
      test.show();
  
      return app.exec();
  }
  </code></pre>
  
  <p>the program only draws the first 2 parts and stops (the sector should have 10 equal parts it has only 2)</p>
  
  <p>I don't understand why it stops drawing. if I cut the sector in two it works fine but starting with 3 it only draws 2 parts</p>
  
  <p>summary of the problem : <a href="http://i.imgur.com/Mssjisd.png" rel="nofollow">http://i.imgur.com/Mssjisd.png</a>
  (image 1, sector divided in 1)
  (image 2, sector divided in 2)
  (image 3, sector divided in 3)
  (image 4, sector divided in 10)</p>