Results 1 to 4 of 4

Thread: Bordered Line/ Point or any closed Figure

  1. #1
    Join Date
    May 2017
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Bordered Line/ Point or any closed Figure

    Hi,
    As for many days I was trying to get a line or point or any closed figure which will have borders around it. By use of QPainter with specific QPen or QBrush it is drawing (using drawLine, drawpoint, drawPolyline etc) only single color figure.
    Is there any way to get closed figure with border around line. Capture.JPG

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Bordered Line/ Point or any closed Figure

    Use QPainterPath
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    May 2017
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Bordered Line/ Point or any closed Figure

    Quote Originally Posted by Santosh Reddy View Post
    Use QPainterPath
    Actually I searched for possibility of doing this but could find any way, even with QPainterPath. Can you please tell me how to use QPainterPath for the same?

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Bordered Line/ Point or any closed Figure

    Not sure what exactly what you want to do, anyway here is an example to use QPainterPath.
    Qt Code:
    1. class MyWidget : public QWidget
    2. {
    3. public:
    4. explicit MyWidget(QWidget * parent = 0)
    5. : QWidget(parent) { }
    6.  
    7. protected:
    8. void paintEvent(QPaintEvent * event)
    9. {
    10. QPainter painter(this);
    11.  
    12.  
    13. const QRect rect = event->rect();
    14. const QPoint center = rect.center();
    15. const int height = rect.height() / 4;
    16. const int width = rect.width() / 4;
    17.  
    18. path.moveTo(center);
    19. path.moveTo(center.x() , center.y() - height);
    20. path.lineTo(center.x() + width , center.y() - height);
    21. path.lineTo(center.x() + width , center.y());
    22. path.lineTo(center.x() + width , center.y() + height);
    23. path.closeSubpath();
    24.  
    25. painter.setPen(QPen(QBrush(Qt::red), 5));
    26. painter.drawPath(path);
    27. painter.fillPath(path, QBrush(Qt::CrossPattern));
    28. }
    29. };
    30.  
    31. int main(int argc, char *argv[])
    32. {
    33. QApplication app(argc, argv);
    34.  
    35. MyWidget widget;
    36. widget.show();
    37.  
    38. return app.exec();
    39. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. in qwt plot selected region need to find max graph line point
    By chandrasekhar.embedded in forum Qwt
    Replies: 4
    Last Post: 8th March 2016, 09:42
  2. Replies: 1
    Last Post: 26th November 2011, 05:56
  3. Trouble animating line point
    By Qtal in forum Newbie
    Replies: 0
    Last Post: 16th February 2011, 19:34
  4. Draw figure underneath other figure
    By Mnemonic in forum Qt Programming
    Replies: 0
    Last Post: 7th April 2010, 14:38
  5. Replies: 1
    Last Post: 3rd December 2009, 15:23

Tags for this Thread

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.