Important: Please read the Qt Code of Conduct -

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": and use "QPainter":

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


  • Hi,

    you could have a look at "the chart item view example": 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)
    if (this->ctype==Nightcharts::Pie)
    pW = 0;
    double pdegree = 0;

      QLinearGradient gradient(cX+0.5*cW,cY,cX+0.5*cW,cY+cH*2.5);
      //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;
      QPen pen;
      for (int i=0;i<pieces.size();i++)
        pdegree = 3.6*pieces[i].pPerc;
        palpha += pdegree;


    my idea is when user clicks on a pie, get the RGB at that particular co-ordinates(X,Y) 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