Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Drawing cross-platform pie chart on a design form
Forum Updated to NodeBB v4.3 + New Features

Drawing cross-platform pie chart on a design form

Scheduled Pinned Locked Moved 3rd Party Software
7 Posts 5 Posters 6.4k 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
    KennedyDayala
    wrote on last edited by
    #1

    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,

    Never Ever Give Up

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

      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

      http://anavi.org/

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        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.

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dialingo
          wrote on last edited by
          #4

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

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

            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

            Never Ever Give Up

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              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?

              1 Reply Last reply
              0
              • K Offline
                K Offline
                KennedyDayala
                wrote on last edited by
                #7

                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...

                Never Ever Give Up

                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