Getting a QtChartView inside of a QGraphicsView
-
Hi,
i have added a QGraphicsView to a .ui file.
In the according class i make a QChartView and want to show that chart in the QGraphicsView.I have tried the following things, but they did not work:
1.)
QChartView* tmp = new QChartView(...);
ui->graphics_view = tmp;2.)
QChartView* tmp = new QChartView(...);
QGraphicsView* graphics_view = new QGraphicsView(tmp);
ui->graphics_view = tmp;The two methods do not work and i cannot really find a way to get a chartview inside of my graphics view.
Can not be too hard to do what i want, or is it? -
i found a great answer by "eyllanesc" on stackoverflow right here:
https://stackoverflow.com/questions/48362864/how-to-insert-qchartview-in-form-with-qt-designerit is possible to right click the graphics view in the ui editor and then in the menu click on promote to.
There you can type "QChartView" in the promoted class name field and "QtCharts" in the Header File field.Then it is possible to go to the code and just say ui->graphics_view->setChart(&chart);
-
Hi,
You are just replacing a pointer with something different. It's even surprising that it's compiling at all.
Since QChartView is widget, use the addWidget method from the QGraphicsScene that you set on your QGraphicsView.