Unsolved How to re(?: paint, display, draw, ...) or update graphicsview after updating
-
With a (derived object of) qchart in a (derived object of) qgraphicsview, how do you re(?: paint, display, draw) or update the chart after its series points are updated (what function of qchart or qgraphicsscene or qgraphicsview do you call for this task)? a sample code attached below.
view.cpp:
void View::updateChart(QString startDateTime, QString endDateTime) { m_series->removePoints(0, m_series->points().count()); // Variable declaration and database initialization if (db.open()) { QSqlQuery query(db); ... if (query.exec(queryString)) { while (query.next()) { // Assignment of input to m_series m_series->append(the input); } } db.close(); } // re(?: paint, display, draw, ...) }
view.h:
class View : public QGraphicsView { Q_OBJECT public: View(QWidget *parent = Q_NULLPTR); ~View(); void updateChart(QString startDateTime, QString endDateTime); private: Scene *m_scene; Chart *m_chart; QtCharts::QLineSeries *m_series; QtCharts::QDateTimeAxis *m_axisX; QtCharts::QValueAxis *m_axisY; QGraphicsSimpleTextItem *m_coordX; QGraphicsSimpleTextItem *m_coordY; };
view.cpp:
View::View(QWidget *parent) : QGraphicsView(parent) { m_scene = new Scene(); m_chart = new Chart(); m_series = new QtCharts::QLineSeries(m_chart); m_axisX = new QtCharts::QDateTimeAxis(m_chart); m_axisY = new QtCharts::QValueAxis(m_chart); m_coordX = new QGraphicsSimpleTextItem(m_chart); m_coordY = new QGraphicsSimpleTextItem(m_chart); m_chart->setGeometry(0, 0, 1400, 800); m_chart->addSeries(m_series); m_axisX->setFormat("d MMM yyyy"); m_chart->addAxis(m_axisX, Qt::AlignBottom); m_series->attachAxis(m_axisX); m_axisY->setLabelFormat("%.6f"); m_chart->addAxis(m_axisY, Qt::AlignLeft); m_series->attachAxis(m_axisY); m_scene->addItem(m_chart); setScene(m_scene); }
-
Hi
m_chart->update() will not do it ? -
No, it would not.
-
@vorlket
ok?!
And repaint() either ? -
No, not with empty argument. It may work with QRect(F) argument referring to the graphics(item/scene/view), perhaps?
-
@vorlket
Nope the QRect is must likely a clipping / update area.Then Im not sure. I only tried QChart briefly and there it
was enough to append the data and it would update.Wait some hours. Some of the others have used the Chart module far more than me. There
must be something simple. -
Remove then add item back works and this is what setChart method of QChartView seems to do. Not sure if this is efficient if there are many items and only a few of them change.