Results 1 to 5 of 5

Thread: line with outline

  1. #1
    Join Date
    Nov 2011
    Posts
    79
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default line with outline

    I still trying to find the fastest way to draw line with outline. Currently it work with next code:

    Qt Code:
    1. void TestWidget::paintEvent(QPaintEvent *)
    2. {
    3. QPainter painter(this);
    4. painter.setRenderHints(QPainter::Antialiasing);
    5. path.moveTo(100,50);
    6. path.lineTo(600,50);
    7. path.lineTo(700,400);
    8. path.lineTo(50,400);
    9. path.moveTo(300,50);
    10. path.lineTo(300,450);
    11. QPen pen(QColor(255, 0, 0));
    12. painter.setPen(pen);
    13. QBrush brush(QColor(255,255,0));
    14. painter.setBrush(brush);
    15. stroker.setWidth(10);
    16. stroker.setCapStyle(Qt::RoundCap);
    17. stroker.setJoinStyle(Qt::RoundJoin);
    18. path = stroker.createStroke(path);
    19. painter.drawPath(path);
    20. }
    To copy to clipboard, switch view to plain text mode 

    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.
    path.pngpath.png

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: line with outline

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2011
    Posts
    79
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: line with outline

    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.
    Attached Images Attached Images

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: line with outline

    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?

  5. #5
    Join Date
    Nov 2011
    Posts
    79
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: line with outline

    уе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.

Similar Threads

  1. QWidget, only draw outline!
    By kinglui987 in forum Qt Programming
    Replies: 4
    Last Post: 17th May 2013, 06:26
  2. How to get rid of red outline on button last clicked?
    By briankeeney in forum Qt Programming
    Replies: 3
    Last Post: 23rd January 2013, 17:59
  3. QgraphicsSimpleTextItem, QPen outline
    By user14921 in forum Qt Programming
    Replies: 1
    Last Post: 9th October 2011, 16:07
  4. QGraphicTextItem and outline
    By eric_vi in forum Qt Programming
    Replies: 12
    Last Post: 17th October 2010, 20:47
  5. Line Outline?
    By jon-ecm in forum Qt Programming
    Replies: 0
    Last Post: 23rd April 2009, 00:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.