'Qwt shows old axes and titles on a new plot
I am trying to use Qwt in my project. I need to draw a plot which can be replaced by another based on some conditions.
My widget is created with the following code:
QStackedWidget *stackedWidget = new QStackedWidget(ui->m_capacitancesWidget);
for(int i = 0; i < sensors; ++i) {
QwtPlot *plot = new QwtPlot();
m_capacitancesPlots.push_back(plot); // convenience vector for easy access to plots
plot->setTitle(tr("Mutual capacitances"));
plot->setCanvasBackground(Qt::white);
plot->insertLegend(new QwtLegend());
QwtPlotCurve *curve = new QwtPlotCurve();
curve->setTitle(tr("Sensor %1").arg(1));
curve->setPen(Qt::green, 1);
curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
curve->attach(plot);
// actually I add another two curves which have some data, but I omit it in this snippet
stackedWidget->addWidget(plot);
}
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(stackedWidget);
ui->m_capacitancesWidget->setLayout(layout);
Here is my widget:
Sometimes I am loading new data and want to refresh the widget. Since there could be different number of sensors and so on, I call the following code to clean things up and then the same code above to create the view from scratch:
for(int i = 0; i < m_capacitancesPlots.size(); ++i)
m_capacitancesPlots[i]->detachItems(QwtPlotItem::Rtti_PlotItem, true);
m_capacitancesPlots.clear();
if(ui->m_capacitancesWidget->layout())
delete ui->m_capacitancesWidget->layout();
But after this, my widget looks like this:
Axes are doubled, titles are doubled. Plots seem to be ok, but when I draw the third one (green in legend), it's not visible. It seems that although QStackedWidget and QwtPlot are completely new, I see some cached old QwtPlot. How to properly clean my widget and draw new QwtPlot?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


