PDA

View Full Version : Draw multiple color line



karankumar1609
17th August 2013, 06:42
Hello all.,

I got stuck somewhere in drawing a line with two colors.
Well i want to draw horizontal, vertical, slant lines with two colors one is above the other just like a sandwich.
eg.. "======================================" just like this. above line of different color and lower line of different color. but without any space in between both.

i have tried



QLinearGradient gradient1;
gradient1.setColorAt(0.0, Qt::darkBlue);
gradient1.setColorAt(0.1, Qt::red);
painter.setPen(QPen(QBrush(gradient1), penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));


but nothing works for me. it just draw line of color red ...

Any idea how to make it possible?

Santosh Reddy
17th August 2013, 09:07
Draw two different lines with different colors

karankumar1609
17th August 2013, 09:48
so this means i have to calculate the initial position and ending position of other line with respect to the current line.?
is there any painter property or something which can do this. even if i draw line or if i draw curve or any other shape.

Santosh Reddy
17th August 2013, 12:37
so this means i have to calculate the initial position and ending position of other line with respect to the current line.?
Yes, based on the pen width, and orientation.


is there any painter property or something which can do this. even if i draw line or if i draw curve or any other shape.
Have a look at QPainter::rotate(), it might be of help.

Do want to draw these line on one widget, or each of these is an indipendent widget?

karankumar1609
19th August 2013, 04:28
i just want to draw these lines on a single widget.