Results 1 to 8 of 8

Thread: Draw line with border

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

    Question Draw line with border

    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.

  2. #2
    Join Date
    Aug 2013
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Draw line with border

    What about setStyleSheet("border: 1px black;"); ?

  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: Draw line with border

    How can I do that?
    What about speed in this case?
    I need very fast drawing.

  4. #4
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Draw line with border

    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).

    Qt Code:
    1. painter->setPen(Qt::red); // rect will have a border of red color
    2. painter->setBrush(QBrush(Qt::black)); // rect will be filled with black color
    3. painter->drawRect(this->rect());
    To copy to clipboard, switch view to plain text mode 
    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

  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: Draw line with border

    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.

  6. #6
    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: Draw line with border

    Draw a QPainterPath. It can have both the outline and fill. QPainterPathStroker can come in handy.
    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.


  7. #7
    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: Draw line with border

    Quote Originally Posted by folibis View Post
    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.

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

    Default Re: Draw line with border

    Ok, in attached image I described what exactly I need.
    And the code how I do it now:
    Qt Code:
    1. QPoint line1[] = {QPoint(20,200),QPoint(400,200),QPoint(400,300),QPoint(20,300)};
    2. QPoint line2[] = {QPoint(100,100),QPoint(100,400),QPoint(200,400),QPoint(350,100)};
    3. QPen pen;
    4. pen.setCapStyle(Qt::RoundCap);
    5. pen.setJoinStyle(Qt::RoundJoin);
    6. pen.setColor(qRgb(201,199,182));
    7. pen.setWidth(14);
    8. painter.setPen(pen);
    9. painter.drawPolyline(line1,4);
    10. painter.drawPolyline(line2,4);
    11. pen.setColor(qRgb(237,234,200));
    12. pen.setWidth(10);
    13. painter.setPen(pen);
    14. painter.drawPolyline(line1,4);
    15. painter.drawPolyline(line2,4);
    To copy to clipboard, switch view to plain text mode 

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

Similar Threads

  1. To draw a line
    By vinayaka in forum Qt Quick
    Replies: 1
    Last Post: 6th June 2011, 10:53
  2. How draw border in QProgressDialog?
    By kamlesh.sangani in forum Qt Programming
    Replies: 0
    Last Post: 5th June 2009, 11:32
  3. Replies: 2
    Last Post: 5th July 2008, 19:35
  4. Best way to draw a Line
    By JimDaniel in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2008, 09:57
  5. How draw extra border on QGraphicsTextItem?
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 8th July 2007, 15:11

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.