QCustomPlot Discussion and Comments

line style of QPen in QCPLineEndingReturn to overview

Hi everybody!

This may look as a question aimed only for the author, but anybody else who would feel they could enlighten me, please do.

My question is why is does the QCPLineEnding take the pen from the corresponding line with the line style? I tried various combinations, but none looked good when the style of the "parent" line was set to something else than Qt::SolidLine. Taking into account that the brush for the line ending is set hard to Qt::SolidPattern, than why not the pen?

It may look like a triffle, but in two cases the one line change in the source code may get annoying: when a beginner wants his line endings with a solid pen (and this forum shows that there are plenty of those who would struggle to find where to set the property) or when one has been granted a LGPL license (that is my case) and this would be the only changed line to publish, when one would like to honour the spirit of the license.

Hey Pavel, I see your question is quite simple from your point of view, but I don't get what you mean. Could you please explain me a bit better, maybe make some examples too?

By all means! Look at the line-side edges of the line endings in this image: http://s22.postimg.org/obufxczq9/qcp_line_style.png, you'll notice that the border is dashed in the same manner as the line (since the QPen is copied from the line) and I find this style not very pleasing to the eye.

The code in question is as follows:

    
m_line = new QCPItemLine(parent);
parent->addItem(m_line);
m_line->setHead(QCPLineEnding(QCPLineEnding::esDiamond, 32));
m_line->setTail(QCPLineEnding(QCPLineEnding::esDiamond, 32));
m_line->setPen(QPen(m_color, 1.0, Qt::DashLine));

So far the only elegant solution I could come up with is

qcustomplot.cpp
+3597   miterPen.setStyle(Qt::SolidLine);

... which is what the last paragraph on the original post speaks about: change to the source of the QCustomPlot, which although not abig deal is in my LGPL situation a bit uncomfortable.

Thank you for explanation, I got it right now :)

I read the documentation and tried myself a few ways to use a different pen, but it's impossible since the line endings inherit the pen from the line they belong to.

As a workaround you could make a double draw, two identical lines each drawn with a different pen. The line on the bottom should be a straight line with no line ending style applied (QCPLineEnding::esNone); this would be your line body. The line on the top instead should be using a line ending style but a transparent pen (Qt::NoPen); this would provide you the desired line ending style. When overlapping them you should see a nice line with a nice line ending style, but this workaround doubles the amount of memory and time needed to draw the graph.

So I upvote for being able to set a different pen for the QCPLineEnding.