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. How to re(?: paint, display, draw, ...) or update graphicsview after updating
Forum Updated to NodeBB v4.3 + New Features

How to re(?: paint, display, draw, ...) or update graphicsview after updating

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 2.3k 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.
  • V Offline
    V Offline
    vorlket
    wrote on last edited by
    #1

    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);
    }
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      m_chart->update() will not do it ?

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vorlket
        wrote on last edited by
        #3

        No, it would not.

        mrjjM 1 Reply Last reply
        0
        • V vorlket

          No, it would not.

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

          @vorlket
          ok?!
          And repaint() either ?

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vorlket
            wrote on last edited by
            #5

            No, not with empty argument. It may work with QRect(F) argument referring to the graphics(item/scene/view), perhaps?

            mrjjM 1 Reply Last reply
            1
            • V vorlket

              No, not with empty argument. It may work with QRect(F) argument referring to the graphics(item/scene/view), perhaps?

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

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

              1 Reply Last reply
              1
              • V Offline
                V Offline
                vorlket
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved