Results 1 to 3 of 3

Thread: Looking for a simple QwtWidgetOverlay implementation example

  1. #1
    Join Date
    Mar 2013
    Posts
    19
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Looking for a simple QwtWidgetOverlay implementation example

    Hi,
    I'm facing a small problem. My application plots a 3D cube (f.e. XYZ data). I have 3 plots using QwtPlotSpectrogram, one for ZX, one for ZY and one for XY.
    Each plot emit moved signal through a derived QwtPlotPicker using a QwtPickerTrackerMachine machine state. the signal emitted from a plot is used to display a marker on the other plots to show the corresponding projected position (see figure attached). In this example the mouse lies in the plot below with the green rubber, then the markers (small red rectangles) will be plotted on the above plots.

    The problem is, it slows down a lot my picker rubber when I move the mouse in a plot. This is probably due to replot mechanism that replot the entire plot widget on the other 2 plots to update the small marker position.
    When I disable the code related to the update of red markers position wrt mouse position, there is no lag.

    I tried to seek a solution on google to understanding this lag problem, it seems that I can solve this by using QwtWidgetOverlay instead of QwtPlotMarker (previous thread here)
    I also dig down to qwt code and understood that QwtPlotPicker rubber and so on use QwtWidgetOverlay that explain why they don't lag with the mouse move in general.

    My development skill is limited since I am a physicist and I couldn't easily understand from qwt code how to use QwtWidgetOverlay.
    So my question is simple, can I find a simple example to implement a QwtWidgetOverlay to avoid slow down effects.

    Thanks by advance.

    slowqwt.jpg

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,296
    Thanked 878 Times in 826 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Looking for a simple QwtWidgetOverlay implementation example

    What you need is something like this ( untested ):

    Qt Code:
    1. class Overlay: public QwtWidgetOverlay
    2. {
    3. public:
    4. Overlay( QWidget *canvas ):
    5. QwtWidgetOverlay( canvas )
    6. {
    7. }
    8.  
    9. void setPosition( const QPointF& pos )
    10. [
    11. m_pos = pos;
    12. updateOverlay();
    13. }
    14.  
    15. virtual void drawOverlay( QPainter *painter ) const
    16. {
    17. const QwtPlot* plot = dynamic_cast<const QwtPlot*>( parent()->parent() );
    18.  
    19. const QwtScaleMap xMap = plot->canvasMap( QwtPlot::xBottom );
    20. const QwtScaleMap yMap = plot->canvasMap( QwtPlot::yLeft );
    21.  
    22. const QPointF pos = QwtScaleMap::transform( xMap, yMap, m_pos );
    23.  
    24. painter->setPen( Qt::yellow );
    25.  
    26. painter->drawLine( pos.x(), 0, pos.x(), height() );
    27. painter->drawLine( 0, pos.y(), 0, width() );
    28. }
    29. }
    To copy to clipboard, switch view to plain text mode 
    HTH, Uwe
    Last edited by Uwe; 20th March 2014 at 12:13.

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

    AxelP (21st January 2019)

  4. #3
    Join Date
    Mar 2013
    Posts
    19
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Looking for a simple QwtWidgetOverlay implementation example

    Magic!
    no lag anymore.

    Just remove QPainter local declaration and use the one passed through parameters.

    Thank you very much.
    Last edited by raphael.lencrerot; 20th March 2014 at 11:59.

Similar Threads

  1. Replies: 0
    Last Post: 31st March 2013, 22:17
  2. Qt Multitouch implementation
    By sonulohani in forum Qt Programming
    Replies: 0
    Last Post: 7th June 2012, 07:51
  3. Modbus implementation
    By ShamusVW in forum Qt Programming
    Replies: 14
    Last Post: 21st December 2011, 11:32
  4. Regarding the implementation of QList
    By rachit.gupta in forum Qt Tools
    Replies: 1
    Last Post: 23rd September 2009, 13:41
  5. source and implementation
    By shrikarcse in forum Newbie
    Replies: 6
    Last Post: 29th March 2006, 06:02

Tags for this Thread

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.