Search code examples
c++qtqtcharts

QChart and using QGradients with accelerated OpenGL rendering


What is going wrong:

Currently my chart works completely fine, it has gradients, and single colored series for example:

colored chart with gradients and single colored series

This works fine, but when I enable openGL acceleration (for more performance) on the 3 series using fooSeries->setUseOpenGL(true) the graph turns into this:

enter image description here

As you can see the color for the gradient series turn black, while the single colored series turns white. Also the Rounded Caps and Rounded Joins also seem to have gone. I did some experimentation to see what may be causing it.

Attemped fixes/experimentation:


I color the series as follows:

// fooGradient is a QLinearGradient described elsewhere as an example.
QBrush fooGradientPenBrush = QBrush(fooGradient);
fooPen = new QPen(fooGradientPenBrush, 5, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
//There are actually 2 QPens for two separate gradients in the program, but this is just for the example.

QBrush barPenBrush = QBrush(QRgb(0xFFFFFF));
barPen = new QPen(barPenBrush, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);

Then later attach these pens top their respective series:

fooSeries->setPen(*fooPen);
barSeries->setPen(*barPen);

Then they are attached to the chart. That's it. I will keep experimenting and looking at the documentation to see if I missed something, it may just be that the openGL acceleration only accepts solid colors, but it is said no where in the documentation that I can find. I'll leave a link to the setUseOpenGl documentation if anyone would like to take a look here.


Solution

  • After more research, I seemed to have missed an important detail in the documentation:

    Pen styles and marker shapes are ignored for accelerated series. Only solid lines and plain scatter dots are supported. The scatter dots may be circular or rectangular, depending on the underlying graphics hardware and drivers.

    I still wonder if there is a way to implement rounded corners and what not to accelerated lines.