Hi,
I needed a way to show which QCPGraph is currently selected and I wanted to use some built-in mechanisms instead of setting the width manually. So I came up with the following idea. Since the selected graph is drawn using QCPSelectionDecorator I thought I could use that. Unfortunately, this class doesn't allow to modify the properties of the plottable, but just sets its own properties. If I want to change just the thickness, I can't, I have to change the whole QPen, that means also the colour. My application allows to modify the colour of the plottable in many places, and I wasn't feeling like modifying the decorator each time, so i came up with this:
class PlotThicknessSelectionDecorator : public QCPSelectionDecorator {
public:
explicit PlotThicknessSelectionDecorator(float widthMultipler = 2.0) :
m_SelectedWidthMultipler(widthMultipler) {}
void setWidthMultiplier(float &multiplier) {
m_SelectedWidthMultipler = multiplier;
}
float widthMultiplier() {
return m_SelectedWidthMultipler;
}
// The declaration of this method in qcustomplot.h was modified to be virtual
void applyPen(QCPPainter *painter) const override {
QPen pen = mPlottable->pen();
pen.setWidthF(pen.widthF() * m_SelectedWidthMultipler);
painter->setPen(pen);
}
private:
float m_SelectedWidthMultipler = 2.0;
};virtual void applyPen(QCPPainter *painter) const; // add virtual