PDA

View Full Version : Draw line with border



folibis
23rd August 2013, 01:45
Hello all!
I have one simple question - is it possible to draw line with border?
Now i draw one line with border color and second one over it with fill color and a little thinner.
Looks good but actually I draw 2 lines in place of one. And second problem - if I set style to dashed it looks awful just because inner line thinner then outer one.

cdonts
23rd August 2013, 02:25
What about setStyleSheet("border: 1px black;"); ?

folibis
23rd August 2013, 04:28
How can I do that?
What about speed in this case?
I need very fast drawing.

karankumar1609
23rd August 2013, 05:07
Hello,

You cannot draw a single line with borders. you can draw a rect with pen (which will be the border color) and brush (brush is the fill color of the rect).



painter->setPen(Qt::red); // rect will have a border of red color
painter->setBrush(QBrush(Qt::black)); // rect will be filled with black color
painter->drawRect(this->rect());

folibis
23rd August 2013, 05:52
ehhm ... how can I draw a rectangle with angle? for example, line (10,10) - (50,50)?
and anyway, with rectangle I cannot draw miltiline analog.

P.S. I need it to draw roads in my map app.

wysota
23rd August 2013, 07:55
Draw a QPainterPath. It can have both the outline and fill. QPainterPathStroker can come in handy.

ChrisW67
24th August 2013, 08:00
ehhm ... how can I draw a rectangle with angle? for example, line (10,10) - (50,50)?
QPainter::rotate()

and anyway, with rectangle I cannot draw miltiline analog.
:confused:

folibis
24th August 2013, 13:53
Ok, in attached image I described what exactly I need.
And the code how I do it now:

QPoint line1[] = {QPoint(20,200),QPoint(400,200),QPoint(400,300),QP oint(20,300)};
QPoint line2[] = {QPoint(100,100),QPoint(100,400),QPoint(200,400),Q Point(350,100)};
QPen pen;
pen.setCapStyle(Qt::RoundCap);
pen.setJoinStyle(Qt::RoundJoin);
pen.setColor(qRgb(201,199,182));
pen.setWidth(14);
painter.setPen(pen);
painter.drawPolyline(line1,4);
painter.drawPolyline(line2,4);
pen.setColor(qRgb(237,234,200));
pen.setWidth(10);
painter.setPen(pen);
painter.drawPolyline(line1,4);
painter.drawPolyline(line2,4);

I was not successful with QPainterPathStroker and QPainterPath at all. It just draw closed lines and I really don't know how to use it.
Rectangles ... ok guys, may be you use thermonuclear anisotropic grasper to eat spaghetti :D I just use a fork for that.
It seems too confusing to me to draw a rectangle and rotate it when you need just line )))
And anyway, it will be a bit problematic to connect one this "line" to others.
As I understand it is impossible to draw line with border in Qt now and it is very frustrating to me.
So I'll continue to use my method.
Thanks to all who responded!