How to place a Chart created in main.cpp into a dock widget?
-
Hello everyone, hope all is well! I am currently trying to promote a display a QChart created in the main.cpp file to display in a dock widget contained in my QMainWindow file. I have been trying to do this by creating a widget to host the chart and then promoting the widget to the dock in the main window, but have not quite been able to get it to display. Here is the code I have for my main.cpp file:
QChart *chart1 = new QChart(); chart1->addSeries(series); chart1->setTitle("TitleOne"); chart1->legend()->hide(); QChart *chart2 = new QChart(); chart2->addSeries(series2); chart2->setTitle("Title2"); chart2->legend()->hide(); QChartView *chartView1 = new QChartView(chart1); QChartView *chartView2 = new QChartView(chart2); chartView1->setRenderHint(QPainter::Antialiasing); chartView2->setRenderHint(QPainter::Antialiasing); QChartView c1; QChartView c2; c1.setChart(chart1); c2.setChart(chart2); c1.resize(840,600); c2.resize(840,600); c1.show(); c2.show(); MainWindow w; w.show();
Note: I tested to make sure my charts were working by creating two separate windows. The widget file and MainWindow file both contain default code. I thought that setting the charts in the main file and then finding a way to call them in the widget file would work, but I have had no luck in doing that. With that being said...
How would I get this code to display in the dock through promoting? Or, is there a simpler way to do this, such as creating the chart in the widget file? In the end, the main thing I am asking is how do you display a chart inside a dock widget? Thank you, in advance, for your time and consideration!
-
Hi and welcome to the forums
The promotion feature of QCreator is mostly used for using own customs controls in UI files.
Normally not for Qt classes and it cant really help in this case any wayTo show it a Dock in main window, simply move the code there.
Then when creating the dock, assign the QChartsThere seems to be no idea to create them in main.cpp ?