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:
class GLCanvas: public QwtPlotOpenGLCanvas
{
public:
GLCanvas
( QwtPlot *parent
= NULL ): QwtPlotOpenGLCanvas( parent )
{
setContentsMargins( 1, 1, 1, 1 );
}
protected:
{
painter.setClipRegion( event->region() );
if ( plot )
plot->drawCanvas( &painter );
painter.setPen( palette().foreground().color() );
painter.drawRect( rect().adjusted( 1, 1, 0, 0 ) );
}
};
class GLCanvas: public QwtPlotOpenGLCanvas
{
public:
GLCanvas( QwtPlot *parent = NULL ):
QwtPlotOpenGLCanvas( parent )
{
setContentsMargins( 1, 1, 1, 1 );
}
protected:
virtual void paintEvent( QPaintEvent *event )
{
QPainter painter( this );
painter.setClipRegion( event->region() );
QwtPlot *plot = qobject_cast< QwtPlot *>( parent() );
if ( plot )
plot->drawCanvas( &painter );
painter.setPen( palette().foreground().color() );
painter.drawRect( rect().adjusted( 1, 1, 0, 0 ) );
}
};
To copy to clipboard, switch view to plain text mode
then inside of the Widget constructor I have this code:
QwtPlotOpenGLCanvas *plotCanvas = qobject_cast<QwtPlotOpenGLCanvas *>( canvas() );
if ( plotCanvas == NULL )
{
plotCanvas = new GLCanvas();
plotCanvas
->setPalette
( QColor( "yellow" ) );
setCanvas( plotCanvas );
}
QwtPlotOpenGLCanvas *plotCanvas = qobject_cast<QwtPlotOpenGLCanvas *>( canvas() );
if ( plotCanvas == NULL )
{
plotCanvas = new GLCanvas();
plotCanvas->setPalette( QColor( "yellow" ) );
setCanvas( plotCanvas );
}
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
plotCanvas
->setPalette
( QColor( "yellow" ) );
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
QwtPlot *plot = new QwtPlot(this);
To copy to clipboard, switch view to plain text mode
and then create a curve and do
curve->attach( plot );
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?
Bookmarks