Search code examples
c++qtqgraphicsviewqtopenglqtcharts

QChart z-values not respected when using openGL acceleration?


I'm trying to do something almost exactly the same as the Qt5 callout example, but I've discovered that if you call setUseOpenGL(true) on the series, then the callout appears under the line instead of above it.

This is true no matter what zValue is set to, including m_tooltip->setZValue(std::numeric_limits<qreal>::max());

Is there a workaround for this?

enter image description here


Solution

  • This happens because OpenGL accelerated series works by creating an QOpenGLWidget on top of the actual QGraphicsView, as noted in the documentation of the useOpenGL property:

    If you draw any graphics items on top of a chart containing an accelerated series, the accelerated series is drawn over those items.

    Basically, as the Callout is rendered inside the QGraphicsView, when OpenGL is enabled a QOpenGLWidget is created on top of that QGraphicsView and because that the callout appears below the line.