Unsolved Graphing on the basis of QTableView
-
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 | 400How to make graphics on the basis of these data? On example, where time will be on X, and numbers on Y.
thank you!
-
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? -
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. -
@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
-
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. -
@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 minimalvoid 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); }
-
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 -
@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. -
Hi,
Since you are using the model view classes and to add to @mrjj, you can take inspiration from Item Views Chart example