PDA

View Full Version : line with outline



folibis
19th September 2013, 06:15
I still trying to find the fastest way to draw line with outline. Currently it work with next code:


void TestWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing);
QPainterPath path;
path.moveTo(100,50);
path.lineTo(600,50);
path.lineTo(700,400);
path.lineTo(50,400);
path.moveTo(300,50);
path.lineTo(300,450);
QPen pen(QColor(255, 0, 0));
painter.setPen(pen);
QBrush brush(QColor(255,255,0));
painter.setBrush(brush);
QPainterPathStroker stroker;
stroker.setWidth(10);
stroker.setCapStyle(Qt::RoundCap);
stroker.setJoinStyle(Qt::RoundJoin);
path = stroker.createStroke(path);
painter.drawPath(path);
}

But how can I remove artefacts inside the lines at connection points? It have to look like roads on a map? without inner cross lines.
96109610

wysota
19th September 2013, 07:45
QPainterPath::simplified()

folibis
20th September 2013, 05:20
Yes, thanks for this tip, it was very useful.
But I found that QPainterPath::simplified() is very very very slow!
For now I found 3 ways to draw line with outline.
1. draw line (QPainter::drawLine) with outline color and width X. then draw the same line with background color and width = X - borderWidth * 2
2. the same way as 1 but using QPainterPath (QPainter::drawPath)
3. draw path from QPainterPath::simplified()

in attachment there are 2 screenshots of all ways.

Expended time:
1. ~ 80 msec.
2. ~ 400 msec.
3. ~ 5000 msec!!

So what, first way seems to be very fast but whet I draw thousands of lines it is not fast enough. And knowing the fact I do double work hurts me.

ChrisW67
20th September 2013, 07:25
QPainterPath::simplified() also gives you a different result, obviously fewer isolated pockets of the outline colour floating a sea of yellow.

What is the purpose of the crazy ant line drawing?

folibis
20th September 2013, 09:22
уеs, result of QPainterPath::simplified() looks a bit different. but it is ok for me.
I make a program for shape file visualization. 10 layers, part of them have about 10000 shapes. so it have to be drawn as fast as possible.