Results 1 to 5 of 5

Thread: Plots won't redraw from a button's click event

  1. #1
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.

    Qt Code:
    1. Plotter::buildSamplePlot(QWidget *parent) {
    2. QwtPlot *myPlot = new QwtPlot(QwtText("Two Curves"), parent);
    3. ...
    4. myPlot.replot();
    5. return myPlot;
    6. }
    To copy to clipboard, switch view to plain text mode 

    The following works fine when called from my constructor:

    Qt Code:
    1. MainWindow::refresh() {
    2. ...
    3. delete curPlot;
    4. curPlot = Plotter::buildSamplePlot(ui->widgetGraph);
    5. delete curPlot;
    6. curPlot = Plotter::buildSamplePlot(ui->widgetGraph);
    7. ...
    8. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Plots won't redraw from a button's click event

    Bump to this. Any clues?

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Plots won't redraw from a button's click event

    What about plot->show() ?

    Uwe

  4. The following user says thank you to Uwe for this useful post:

    ean5533 (20th March 2009)

  5. #4
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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?)

  6. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

Similar Threads

  1. Replies: 4
    Last Post: 19th February 2009, 11:10
  2. Replies: 2
    Last Post: 4th August 2008, 07:44
  3. On click event for a QPixmap
    By rishid in forum Qt Programming
    Replies: 1
    Last Post: 22nd February 2008, 16:12
  4. Replies: 7
    Last Post: 20th November 2007, 12:15
  5. The event fired by the mouse click on the frame
    By Placido Currò in forum Qt Programming
    Replies: 8
    Last Post: 3rd March 2007, 09:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.