Results 1 to 7 of 7

Thread: Refreshing a Custom QwtScaleDraw

  1. #1
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Refreshing a Custom QwtScaleDraw

    Hi, I have reimplemented QwtScaleDraw.

    When I start plotting data I would like the current time to be displayed. Not the time when the application started.

    I reset my QTime, It does eventually display the right time after the plot starts to auto scale.

    Thanks in advance
    Brendan

    Qt Code:
    1. class TimeScaleDraw: public QwtScaleDraw
    2. {
    3. public:
    4. TimeScaleDraw();
    5. void start();
    6. virtual QwtText label(double) const;
    7.  
    8. private:
    9. QTime m_base_time;
    10. };
    11.  
    12. TimeScaleDraw::TimeScaleDraw()
    13. {
    14. start();
    15. }
    16.  
    17. QwtText TimeScaleDraw::label(double v) const
    18. {
    19. QTime upTime = m_base_time.addMSecs((int)v);
    20.  
    21. return upTime.toString("H:mm:ss.zzz");
    22. }
    23.  
    24. void TimeScaleDraw::start()
    25. {
    26. m_base_time.start();
    27. //TODO: DO SOMETHING HERE TO REFRESH QwtScaleDraw???
    28. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: Refreshing a Custom QwtScaleDraw

    QwtPlot::replot()

    Uwe

  3. #3
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Refreshing a Custom QwtScaleDraw

    I tried calling qwtPlot->replot() after start() was called, this didn't make any difference.

    I have also tried passing the QwtPlot pointer to the class and running replot() with that pointer. This didn't make any difference.

    When I added QwtPlot::replot() to the class it gave the following error:
    "cannot call member function 'virtual void QwtPlot::replot()' without object"
    I tried adding friend classes etc.

    I don't seem to have the same problem with my custom QwtPlotPicker.

    Please excuse my stupidity in advance

  4. #4
    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: Refreshing a Custom QwtScaleDraw

    Qt Code:
    1. TimeScaleDraw* scaleDraw = dynamic_cast<TimeScaleDraw*>( plot->axisScaleDraw( ... ) );
    2. scaleDraw->start();
    3. scaleDraw->invalidateCache();
    4. plot->replot();
    To copy to clipboard, switch view to plain text mode 
    HTH,
    Uwe

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

    grantbj74 (19th March 2012)

  6. #5
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Refreshing a Custom QwtScaleDraw

    The scaleDraw->invalidateCache() gives a protected error when compiling.

    If I put invalidateCache() inside a new function that changes appearance in TimeScaleDraw class: eg ms, sec, clock etc it changes straight away.

    However if invalidateCache() is put in the end of start() time still doesn't update until the plot starts moving etc. I guess this isn't too much of an issue.

    I just use the following for time atm:
    Qt Code:
    1. QwtText TimeScaleDraw::label(double /*v*/) const
    2. {
    3. return m_base_time.toString("H:mm:ss.zzz");
    4. }
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Refreshing a Custom QwtScaleDraw

    The call to invalidateCache() won't cause a replot on its own, it is just a method to ensure that the labels are recalculated the next time there -is- a replot. So after you construct your TimeScaleDraw class, call replot() from where ever you are in the code.

  8. #7
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Refreshing a Custom QwtScaleDraw

    Yeah I was calling replot() last but made no difference.

Similar Threads

  1. Replies: 1
    Last Post: 13th October 2011, 16:52
  2. Replies: 2
    Last Post: 14th September 2011, 07:53
  3. QwtScaleDraw align label to xaxis
    By kja in forum Qwt
    Replies: 1
    Last Post: 21st November 2010, 19:55
  4. Replies: 1
    Last Post: 14th October 2010, 18:56
  5. Threaded refreshing of a TreeView with custom model
    By CLRS530 in forum Qt Programming
    Replies: 4
    Last Post: 25th August 2009, 08:23

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.