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. QtCharts with Qt Creator
Forum Updated to NodeBB v4.3 + New Features

QtCharts with Qt Creator

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtdesignerqtchartqwidget
2 Posts 2 Posters 3.1k Views
  • 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.
  • M Offline
    M Offline
    Mattia
    wrote on 2 Oct 2017, 21:02 last edited by Mattia 10 Mar 2017, 20:34
    #1

    Dear all,

    I am trying to add a QChart to a simple dialog window, but I encounter some problems: I have created the dialog and I have inserted a QWidget from QtDesigner. Then I have promoted the widget to a class named ChartWidget and I have created this class that result like that:

    ChartWidget.h

    #include <QWidget>
    
    class ChartWidget : public QWidget
    {
    	Q_OBJECT
    
    public:
    	explicit ChartWidget(QWidget *parent = 0);
    };
    

    ChartWidget.cpp

    #include "ChartWidget.h"
    #include <QtCharts/QChartView>
    #include <QtCharts/QLineSeries>
    #include <QtWidgets/QGridLayout>
    
    
    using namespace QtCharts;
    
    ChartWidget::ChartWidget(QWidget *parent) :
    	QWidget(parent)
    {
    	QLineSeries *series = new QLineSeries();
    	series->setName("Line 1");
    
    	series->append(0, 6);
    	series->append(2, 4);
    	series->append(3, 8);
    	series->append(7, 4);
    	series->append(10, 5);
    	*series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2);
    
    	QChart *chart = new QChart();
    	chart->setAnimationOptions(QChart::AllAnimations);
    
    	chart->legend()->hide();
    	chart->addSeries(series);
    	chart->createDefaultAxes();
    	chart->setTitle("Simple line chart example");
    
    	QChartView *chartView = new QChartView(chart);
    	chartView->setRenderHint(QPainter::Antialiasing);
    	chartView->setMinimumSize(640, 480);
    	/*
    	// create main layout
    	QGridLayout *mainLayout = new QGridLayout;
    	mainLayout->addWidget(chartView, 1, 1);
    	mainLayout->setColumnStretch(1, 1);
    	mainLayout->setColumnStretch(0, 0);
    	setLayout(mainLayout);*/
    }
    

    But with this implementation, when i compile, the dialog window opens correctly, but it is empty. Instead if I uncomment the last lines in the cpp file, I see the chart correctly, but I am not controlling the layout with the QtDesigner anymore. How can I see the chart using the QtDesigner to setup the layout?

    Thanks

    1 Reply Last reply
    0
    • 6 Offline
      6 Offline
      6thC
      wrote on 4 Oct 2017, 03:41 last edited by
      #2

      It might not be the answer but it is a answer. I declare my charts using QML to maintain declarative / visual design.

      I only control them from C++ with C++ data. I do all the processing of dynamic axis ranges inside that, I do stupidly high frequency updates.

      I'd recommend, if you very frequently update your line series like I do to use: void QXYSeries::replace(QVector<QPointF> points) (or QList...)

      and also set your LineSeries to use open GL either from QML or C++ works fine, you do lose some functionality but it saves using canvas (which is slower) if you have lots of points of data, with many fast updates.

      HTH

      1 Reply Last reply
      0

      1/2

      2 Oct 2017, 21:02

      • Login

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