QCustomPlot Discussion and Comments

Strange Behavior with OpenGLReturn to overview

Hi,

I have two QCustomPlot on the main window to display real time data with OpenGL enabled for both of them.
I can see some strange behavior for the first one (first to be instantiate) when moving the cursor on it. For a short moment (like a glitch) this plot is exactly the same as the second plot (data/legend/style...)

When OpenGL is disabled, i cant see this behavior.

Is there any settings that i can modify to avoid that ?

You are not alone, I also have encountered this behavior. I dont know what to do.

This is a problem with the OpenGL context... If the QCustomPlots are on different windows, this doesn't happen too...

See :
http://www.qcustomplot.com/index.php/support/forum/1153

But I didn't find anything to solve this problem...

Also looking for a solution.

The strange behavior when OpenGL is set for multiple QCustomPlot widgets in a single instance can be fixed as follows:

When we create multiple QCustomPlot Widgets in a single instance (or single process), somehow QOpenGLContext::currentContext() is getting other OpenGL context.

Each time when the widget has to draw, it is calling the QCPPaintBufferGlFbo::draw(QCPPainter *painter) function. Here, the QopenGL's current context is not checked with the widget's mGLContext like in other QCPPaintBufferGlFbo class functions. So adding this check and making the mGLContext as current Context solved the issue.

Change the following function in qcustomplot.cpp

void QCPPaintBufferGlFbo::draw(QCPPainter *painter) const
{
  if (!painter || !painter->isActive())
  {
    qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed";
    return;
  }
  if (!mGlFrameBuffer)
  {
    qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?";
    return;
  }
  painter->drawImage(0, 0, mGlFrameBuffer->toImage());
}

To

void QCPPaintBufferGlFbo::draw(QCPPainter *painter) const
{
  if (!painter || !painter->isActive())
  {
    qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed";
    return;
  }
  if (!mGlFrameBuffer)
  {
    qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?";
    return;
  }

  //Add these 2 lines
  if (QOpenGLContext::currentContext() != mGlContext.data())
    mGlContext.data()->makeCurrent(mGlContext.data()->surface());

  painter->drawImage(0, 0, mGlFrameBuffer->toImage());
}