How to change QLineSeries width?

6.4k views Asked by At

I need to set width of QLineSeries
I do

QPen pen = series->pen();
pen.setWidth(1);
series->setPen(pen);

And it works but color is changed to black. What do I need to do to set only the width?

1

There are 1 answers

1
Jablonski On

You need to specify brush with needed color. F.e.

QPen pen = series->pen();
pen.setWidth(1);
pen.setBrush(QBrush("red")); // or just pen.setColor("red");
series->setPen(pen);

Update:

But can I set width without missing current color?

It can be done if you will set pen after addSeries() call. Because defaultColor (color of your pen) in your case is just (1,0,0,0), default color (this kind of blue color on the plot) depends on chosen theme and appears after you call chart->addSeries(series); So only way to achieve what you want is smth like next:

QChart *chart = new QChart();
chart->addSeries(series); // addSeries must be called first

QPen pen = series->pen();
pen.setWidth(1);
series->setPen(pen);