Results 1 to 5 of 5

Thread: Plotting data with QwtPlotOpenGLCanvas

  1. #1
    Join Date
    Jul 2016
    Posts
    57
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Question Plotting data with QwtPlotOpenGLCanvas

    Trying to get simple first template example for plotting using the brand new QwtPlotOpenGLCanvas class which is based on QOpenGLWidget

    I was trying to get necessary parts from the refreshtest example.

    Here is what I have first separately in my widget.cpp as a declaration:
    Qt Code:
    1. class GLCanvas: public QwtPlotOpenGLCanvas
    2. {
    3. public:
    4. GLCanvas( QwtPlot *parent = NULL ):
    5. QwtPlotOpenGLCanvas( parent )
    6. {
    7. setContentsMargins( 1, 1, 1, 1 );
    8. }
    9.  
    10. protected:
    11. virtual void paintEvent( QPaintEvent *event )
    12. {
    13. QPainter painter( this );
    14. painter.setClipRegion( event->region() );
    15.  
    16. QwtPlot *plot = qobject_cast< QwtPlot *>( parent() );
    17. if ( plot )
    18. plot->drawCanvas( &painter );
    19.  
    20. painter.setPen( palette().foreground().color() );
    21. painter.drawRect( rect().adjusted( 1, 1, 0, 0 ) );
    22. }
    23. };
    To copy to clipboard, switch view to plain text mode 

    then inside of the Widget constructor I have this code:
    Qt Code:
    1. QwtPlotOpenGLCanvas *plotCanvas = qobject_cast<QwtPlotOpenGLCanvas *>( canvas() );
    2. if ( plotCanvas == NULL )
    3. {
    4. plotCanvas = new GLCanvas();
    5. plotCanvas->setPalette( QColor( "yellow" ) );
    6.  
    7. setCanvas( plotCanvas );
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    Here are my concerns/questions:

    1) When I tried the above experiment with old QwtPlotGLCanvas, I did have a proper widget with yellow colored canvas. So I assume it was working. But after I changed it to be QwtPlotOpenGLCanvas based, mo matter what palette I set with
    Qt Code:
    1. plotCanvas->setPalette( QColor( "yellow" ) );
    To copy to clipboard, switch view to plain text mode 
    the color is always black, why? Is it a bug, or am I supposed to set something more when changing to QwtPlotOpenGLCanvas ?

    2) How to plot data now? For example, before, without OpenGL, we would do something like this
    Qt Code:
    1. QwtPlot *plot = new QwtPlot(this);
    To copy to clipboard, switch view to plain text mode 
    and then create a curve and do
    Qt Code:
    1. curve->attach( plot );
    To copy to clipboard, switch view to plain text mode 
    However; right now I cannot attach curve like that because it will complain that argument to the attach function is not of QwtPlot * type, so How am I supposed to do it properly?

  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: Plotting data with QwtPlotOpenGLCanvas

    Quote Originally Posted by r2com View Post
    Trying to get simple first template example for plotting using the brand new QwtPlotOpenGLCanvas class which is based on QOpenGLWidget
    Note, that the implementation is not done - so don't expect it being as stable as you can expect for the other Qwt classes. And better don't start with modifying the refreshtest example - AFAIR something is broken in combination with QOpenGLWidget ( black content ) - any other example should be fine.

    Also don't expect too much from QOpenGLWidget - it is using the same paint engine as the QGLWidget. I can even imagine QGLWidget being slightly faster for your use case because of not buffering to an internal FBO.On the other side interactive elements ( f.e rubberbands ) do work with QOpenGLWidget only, but a standard QWidget seems to be even better for that use case.
    Quote Originally Posted by r2com View Post
    How to plot data now?
    There is no difference - the problem you have described is in your application code.

    Uwe

  3. #3
    Join Date
    Jul 2016
    Posts
    57
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Plotting data with QwtPlotOpenGLCanvas

    Alright Uwe, I think I have worked it out. Here is a code of my widget, can you tell me if it looks like an OK method to plot using the OpenGL capability through your QwtPlotOpenGLCanvas method (at least it runs and displays properly, with right colors as well):

    Qt Code:
    1. Widget::Widget(QwtPlot *parent) :
    2. QwtPlot(parent),
    3. ui(new Ui::Widget)
    4. {
    5. ui->setupUi(this);
    6.  
    7. QwtPlotOpenGLCanvas *plotCanvas = new QwtPlotOpenGLCanvas();
    8. plotCanvas->setPalette( QColor("khaki") );
    9. setTitle("Test Plot");
    10. setCanvas( plotCanvas );
    11.  
    12. setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
    13. setAxisScale( QwtPlot::xBottom, 0.0, 7.0 );
    14. insertLegend( new QwtLegend() );
    15. QwtPlotGrid *grid = new QwtPlotGrid();
    16. grid->attach( this );
    17.  
    18. QwtPlotCurve *curve = new QwtPlotCurve();
    19. curve->setTitle( "Some Points" );
    20. curve->setPen( Qt::blue, 4 ),
    21. curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
    22.  
    23. QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
    24. QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) );
    25. curve->setSymbol( symbol );
    26.  
    27. QPolygonF points;
    28. points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
    29. << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
    30. << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );
    31. curve->setSamples( points );
    32.  
    33. curve->attach( this );
    34.  
    35. resize( 600, 400 );
    36. show();
    37. }
    To copy to clipboard, switch view to plain text mode 

    Specifically, is what I do in lines #33, #16, #5 and especially line #7 is normal thing to do in order to achieve this plotting? My whole Widget is based on QwtPlot.
    Last edited by r2com; 16th August 2016 at 23:14.

  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: Plotting data with QwtPlotOpenGLCanvas

    Sure, simply assign a different type of canvas - that's all.

    When working with trunk you might also want to check QwtPlotCurve::FilterPointsAggressive. When flooding a oscilloscope alike plot with many points this filter might improve the performance significantly ( regardless of the type of canvas ).

    Uwe

  5. #5
    Join Date
    Jul 2016
    Posts
    57
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Plotting data with QwtPlotOpenGLCanvas

    Quick question, does the new QwtPlotOpenGLCanvas support all the zooming features?

    found that it does, created another topic not to contaminate this thread, here: http://www.qtcentre.org/threads/6662...809#post292809
    Last edited by r2com; 17th August 2016 at 19:21.

Similar Threads

  1. QWT- Help with plotting data from a vector.
    By rockinfresh in forum Qwt
    Replies: 5
    Last Post: 21st January 2014, 07:23
  2. Plotting 3d using non-grid data
    By warcraff123456 in forum Qt Programming
    Replies: 1
    Last Post: 15th March 2013, 18:40
  3. QT 4.5 and Plotting data
    By Lezer in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 6th September 2012, 13:11
  4. axes for plotting data
    By timmu in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2012, 12:19
  5. Plotting socket data
    By catto in forum Qwt
    Replies: 4
    Last Post: 6th March 2011, 08:01

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.