PDA

View Full Version : Plots won't redraw from a button's click event



ean5533
12th March 2009, 02:10
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.


Plotter::buildSamplePlot(QWidget *parent) {
QwtPlot *myPlot = new QwtPlot(QwtText("Two Curves"), parent);
...
myPlot.replot();
return myPlot;
}

The following works fine when called from my constructor:


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

ean5533
20th March 2009, 15:35
Bump to this. Any clues?

Uwe
20th March 2009, 16:05
What about plot->show() ?

Uwe

ean5533
20th March 2009, 17:18
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?)

Uwe
21st March 2009, 13:51
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