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);
You need to specify brush with needed color. F.e.
Update:
It can be done if you will set pen after
addSeries()
call. BecausedefaultColor
(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 callchart->addSeries(series);
So only way to achieve what you want is smth like next: