Anduril28 Anduril28 - 1 month ago 62
C++ Question

How do you display a QChartView in a Custom Widget?

I have a QChart that I've assigned to a QChartView. In the example I've been following the chart is displayed, in main.cpp, as:

window.setCentralWidget(chartView);


In my project I want to utilize the designer and as such have created a custom widget, but it's not displaying the QChart. I found an example where they assigned they assigned the view to a layout and then set the layout, as such:

mainLayout = new QGridLayout;
mainLayout->addWidget(chartView, 0, 0);
setLayout(mainLayout);


But this seems to mess with the layout of all the other widgets within the window. How do I get the Custom Widget to display my chartView?

Thank you!

Answer

I made the class inherit from QChartView (which inherits QWidget) instead of QWidget, then did:

setChart(myChart);

Thanks.

Comments