'How to insert QChartView in form with Qt Designer?
I want to add QChart to the form. But I can't find it in the Widget Box. So I created it in the code. How can I insert it in QWidget or QFrame or something else?
I want to set area of that widget in QtDesigner.
Solution 1:[1]
Let me add something here for the answer below (thanks for that!)
I had some additional steps for using
QTcreator 4.11.0
on
Ubuntu 20.04.3 LTS
First, you need to install not only package
qml-module-qtcharts
But also package
libqt5charts5-dev
Next, for "Option 1: Promoted" below you 1st have to use Button "Add" after entering
Promoted class name: QChartView
and
Header file: QtCharts
Then, you can select it from the "Promoted Classes"
Finally, QTCreator adds to your ui_mainwindow.h (e.g.)
#include <qchartview.h>
and uses
QChartView *graphicsView;
But it does not consider, that type QChartView is defined in "namespace QtCharts" in <qchartview.h>. Therefore, type QChartView is not found.
I fixed (hacked) this by adding a "Central.h" to #include for users as a 1st #include file, with content
#ifndef CENTRAL_H
#define CENTRAL_H
#include <QtCharts>
using namespace QtCharts;
#endif // CENTRAL_H
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
