coloring a part of a line (QLineF)
-
Hi,
I am drawing a line using QLineF and QPainter and coloring the same by setting pen color and painter brush.
QLineF line1;
QPen pen = QPen(WHITE,THICKNESS);
painter.setBrush(QBrush(WHITE));
painter.setPen(pen);
painter.drawLine(line1);
But its coloring the whole line(As expected)
Now I want to color some part of the same line with different color like:(No other QLineF object should be used)
Is this possible?
If yes, Please give me some idea.
Thanks in Advance :) -
@Bikram-Shishodia I don't think it is possible but nothing stops you from drawing two lines with different colors.
"No other QLineF object should be used" - why not? It's not a big object. -
@Bikram-Shishodia said in coloring a part of a line (QLineF):
(No other QLineF object should be used)
Is this possible?
No. You need another QLineF object.
-
@Bikram-Shishodia
As said by @jsulm & @JKSH you can use multiple QLine or QLineF with QPainter::drawLines// QPainter::drawLines Options available void QPainter::drawLines(const QVector<QLine> &lines) void QPainter::drawLines(const QVector<QLineF> &lines) etc...
Here is sample code, where you have to draw individual lines without QLine or QLineF
QPainter painter(this); painter.setPen(QPen(Qt::red, 5)); painter.drawLine(100, 50, 150, 50); painter.setPen(QPen(Qt::green, 5)); painter.drawLine(150, 50, 200, 50);
Output: