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. Graphing on the basis of QTableView
Forum Updated to NodeBB v4.3 + New Features

Graphing on the basis of QTableView

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 2.2k Views 2 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.
  • ro12man3R Offline
    ro12man3R Offline
    ro12man3
    wrote on last edited by
    #1

    Hi all!

    My program has a qtableview, where I can see sql query results. There are 2 columns: date and numbers. Example:

    02.03.2016 | 345
    03.03.2016 | 400

    How to make graphics on the basis of these data? On example, where time will be on X, and numbers on Y.

    thank you!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      The fast way is just to paint it yourself.

      But depends on your requirements:

      Do you need to be able to zoom and scroll?
      How many rows do you have?

      1 Reply Last reply
      0
      • ro12man3R Offline
        ro12man3R Offline
        ro12man3
        wrote on last edited by
        #3

        well, now I don't need to be able to zoom and scroll.
        I will sort the data by months, so I think one graphic will be for one year.
        In this variant, it will be no more than 12 rows.
        What about that variant? I want to make function that will automatically build the graphics.

        mrjjM 1 Reply Last reply
        0
        • ro12man3R ro12man3

          well, now I don't need to be able to zoom and scroll.
          I will sort the data by months, so I think one graphic will be for one year.
          In this variant, it will be no more than 12 rows.
          What about that variant? I want to make function that will automatically build the graphics.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @ro12man3
          well if you have only 12 bars then it should fit a screen.

          You could use something like
          http://www.qcustomplot.com/
          for fancy look,

          Alternative (since no zoom / scroll needed)
          You could just draw it to a Pixmap and show in QLabel.

          This is the very basic version. Might be enough ?

          https://www.dropbox.com/s/qwde8lb0fkjrrh3/mycheapgraph.zip?dl=0

          1 Reply Last reply
          1
          • ro12man3R Offline
            ro12man3R Offline
            ro12man3
            wrote on last edited by
            #5

            Normal option, but I need to take the values from the qtableview.
            And preferably that would be under each pillar had an appropriate value, and the left shows, too. Biaxially.
            User need to understand in what date(month) which value corresponds to it.

            mrjjM 1 Reply Last reply
            0
            • ro12man3R ro12man3

              Normal option, but I need to take the values from the qtableview.
              And preferably that would be under each pillar had an appropriate value, and the left shows, too. Biaxially.
              User need to understand in what date(month) which value corresponds to it.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @ro12man3
              well you can easy add text to this sample.
              and take values from other place.
              Maybe also draw some axis etc.
              The code is pretty minimal

              void MainWindow::on_pushButton_released() {
                int h = ui->label->height();
                int w = ui->label->width();
                QPixmap pix(w, h);
                QPainter paint(&pix);
                pix.fill( Qt::white );
                paint.setPen(QColor(0, 0, 0, 255));
                int y = 0;
                int x = 0;
                int bw = 10; // bar width
                for (int barcount = 0; barcount < 12; ++barcount) {
                  paint.setBrush(QColor(255 - x, 34 + x, 255, 255));
                  paint.drawRect(x, h - GetBarHeight(h),  bw, h );
                  x += bw + 4;
                }
                paint.end();
                ui->label->setPixmap(pix);
              }
              
              1 Reply Last reply
              1
              • ro12man3R Offline
                ro12man3R Offline
                ro12man3
                wrote on last edited by
                #7

                I tried, but I can't do that.
                Can you help me with a code?
                This is result in my qtableview: http://fs152.www.ex.ua/show/740143394177/245744196/245744196.png
                I want to make a graphic by every month and sum of all numbers in every month. Like that:
                http://fs143.www.ex.ua/show/740143394177/245747299/245747299.png

                mrjjM 1 Reply Last reply
                0
                • ro12man3R ro12man3

                  I tried, but I can't do that.
                  Can you help me with a code?
                  This is result in my qtableview: http://fs152.www.ex.ua/show/740143394177/245744196/245744196.png
                  I want to make a graphic by every month and sum of all numbers in every month. Like that:
                  http://fs143.www.ex.ua/show/740143394177/245747299/245747299.png

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @ro12man3
                  Hi which part didn't work for you?
                  you can use paint.drawLine to make such diagram.
                  and some drawText.
                  I won't make it for you but u are welcome to ask about details.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Hi,

                    Since you are using the model view classes and to add to @mrjj, you can take inspiration from Item Views Chart example

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    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