Plots won't redraw from a button's click event
I'm running into a slight problem making QwtPlots draw during click events. I can make QwtPlots show up just fine if I create them during (for example) the constructor for my form; however, if I try to create new plots from the click() slot of a button, the plots fail to draw.
I have a static class called Plotter that spits out QwtPlots for me.
Code:
Plotter
::buildSamplePlot(QWidget *parent
) { ...
myPlot.replot();
return myPlot;
}
The following works fine when called from my constructor:
Code:
MainWindow::refresh() {
...
delete curPlot;
curPlot = Plotter::buildSamplePlot(ui->widgetGraph);
delete curPlot;
curPlot = Plotter::buildSamplePlot(ui->widgetGraph);
...
}
I'm deleting the plot and re-creating it simply to show that I can delete and re-create plots just fine, as long as I do it from my form's constructor. However, calling the exact same method above from one of my button's click() slots does not work. All that happens is that the existing plot is deleted, but no new plot is drawn. I've stepped through and seen the the old plot really is deleted, and that a new plot is created (I can call methods on the new graph just fine). However, the newly created plot just doesn't seem to show up.
As far as I can tell, the plot exists but isn't drawing. I've tried forcing the plots to draw themselves by calling .repaint(), .replot(), and even .resize(). None of them had any effect.
Ideas?
Thanks,
-Evan Nelson
Re: Plots won't redraw from a button's click event
Re: Plots won't redraw from a button's click event
What about plot->show() ?
Uwe
Re: Plots won't redraw from a button's click event
Amazing, that worked great. Out of curiosity, any idea why the call to .show() was only needed when creating plots from a .click() event? (Especially when .replot() and .repaint() did nothing?)
Re: Plots won't redraw from a button's click event
QWidget::show shows a widget together with all its children.
When you look at your implementation of main you will see, that you do a show with your main window. This show includes the plot widgets you have created in the constructor.
Uwe