I found where was a problem but I didn't understand why it was so.
Here is a demostration example:
A Qwt plot with a legend
public:
SimplePlot ();
};
SimplePlot::SimplePlot() {
insertLegend
(legend,
QwtPlot::RightLegend);
}
insertLegend
(legend,
QwtPlot::RightLegend);
}
class SimplePlot : public QwtPlot{
public:
SimplePlot ();
SimplePlot (QWidget * widget);
};
SimplePlot::SimplePlot() {
QwtLegend *legend = new QwtLegend(this);
insertLegend(legend, QwtPlot::RightLegend);
}
SimplePlot::SimplePlot (QWidget * widget) : QwtPlot (widget){
QwtLegend *legend = new QwtLegend(this);
insertLegend(legend, QwtPlot::RightLegend);
}
To copy to clipboard, switch view to plain text mode
A code with a bug:
SimplePlot * plot = new SimplePlot (plotWidget); // a problem
//SimplePlot * plot = new SimplePlot; // no problems
plotLayout->addWidget(plot);
plotWidget->setLayout(plotLayout);
tabWidget
->insertTab
(0,
new QLabel(),
"Test Label");
tabWidget->insertTab(1, plotWidget, "Plot");
tabWidget->setMinimumSize(400, 400);
tabWidget->show();
QTabWidget * tabWidget = new QTabWidget;
QWidget * plotWidget = new QWidget;
SimplePlot * plot = new SimplePlot (plotWidget); // a problem
//SimplePlot * plot = new SimplePlot; // no problems
QVBoxLayout * plotLayout = new QVBoxLayout;
plotLayout->addWidget(plot);
plotWidget->setLayout(plotLayout);
tabWidget->insertTab(0, new QLabel(), "Test Label");
tabWidget->insertTab(1, plotWidget, "Plot");
tabWidget->setMinimumSize(400, 400);
tabWidget->show();
To copy to clipboard, switch view to plain text mode
P.S. if I firstly insert the "Plot" tab and secondly the "Test Label" tab everything also looks fine (even if I use a constructor with a parent widget)
Bookmarks