Drawing cross-platform pie chart on a design form



  • Hi all,

    Can anybody help me in drawing a cross-platform pie chart on a design form(dialog) for a desktop application? or lemme know if there are any supporting classes for developing this.

    many thanks,



  • Hi,

    If you want to draw freely in a QWidget or class that inherits it you should overload the protected virtual method "paintEvent":http://doc.qt.nokia.com/latest/qwidget.html#paintEvent and use "QPainter":http://doc.qt.nokia.com/latest/qpainter.html

    I would recommend you to search for a Qt library specialized for charts. I have heard about "Qwt":http://qwt.sourceforge.net/ but I have never used it personally.

    Cheers,
    Leon



  • Hi,

    you could have a look at "the chart item view example":http://doc.qt.nokia.com/4.7/itemviews-chart.html example.

    bq. The Chart example shows how to create a custom view for the model/view framework.

    It's a view that draws a chart, base on a model.



  • You have lots of options:
    KDAB and ICS each offer commercial Qt source code packages which contain lots of charting diagrams.

    GraphicsView is slightly more heavyweight than a naked QPainter but makes drawing easier, (and especially interaction if needed).



  • hi all,

    to continue with..i want to capture the co-ordinates of each pie which is drawn on a dialog when user clicks on a pie and open a new window with corresponding details....can anyone guide me how to

    1. to use the mouse button events
    2. to convert the LP->DP and DP ->LP


  • Well... that would depend on how you choose to draw it, would it not?
    Did you look into the existing offers? Did you note that KDAP's offer is also available as Open Source?



  • This is how my code goes...

    @
    int Nightcharts::draw(QPainter *painter)
    {
    painter->setRenderHint(QPainter::Antialiasing);
    painter->setPen(Qt::NoPen);
    if (this->ctype==Nightcharts::Pie)
    {
    pW = 0;
    double pdegree = 0;

      //Options
      QLinearGradient gradient(cX+0.5*cW,cY,cX+0.5*cW,cY+cH*2.5);
      gradient.setColorAt(1,Qt::black);
    
    
      //Draw
      //pdegree = (360/100)*pieces[i].pPerc;
      if (shadows)
      {
          double sumangle = 0;
          for (int i=0;i<pieces.size();i++)
          {
              sumangle += 3.6*pieces[i].pPerc;
          }
          painter->setBrush(Qt::darkGray);
          painter->drawPie(cX,cY+pW+5,cW,cH,palpha*16,sumangle*16);
      }
    
      QPen pen;
      pen.setWidth(2);
    
      for (int i=0;i<pieces.size();i++)
      {
        gradient.setColorAt(0,pieces[i].rgbColor);
        painter->setBrush(gradient);
        pen.setColor(pieces[i].rgbColor);
        painter->setPen(pen);
        pdegree = 3.6*pieces[i].pPerc;
        painter->drawPie(cX,cY,cW,cH,palpha*16,pdegree*16);
        palpha += pdegree;
      }
    

    @

    my idea is when user clicks on a pie, get the RGB at that particular co-ordinates(X,Y)..compare the RGB with pieces[i].rgbColor..get the pie name and hence diaplay the details in a new window..

    but I need your help in writing the code to get the pixel color of a window on mouse click..

    many thanks in advance...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.