Results 1 to 5 of 5

Thread: how to draw points with qpainter?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2011
    Posts
    81
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default how to draw points with qpainter?

    Qt Code:
    1. void MainWindow::mousePressEvent(QMouseEvent *f)
    2. {
    3. point=f->pos();
    4. y=1;
    5. update();
    6. }
    7.  
    8. void MainWindow::paintEvent(QPaintEvent *e)
    9. {
    10. QPainter painter(this);
    11. QPen linepen(Qt::red);
    12. linepen.setCapStyle(Qt::RoundCap);
    13. linepen.setWidth(30);
    14. painter.setRenderHint(QPainter::Antialiasing,true);
    15. painter.setPen(linepen);
    16. if(y==1)
    17. painter.drawPoint(point);
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 

    i have used the code. but draws only single point. when i click to draw a second point the first point will disappear. at a time only one point will appear..

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: how to draw points with qpainter?

    Its because paintEvent clears the widget before painting, so everything previously painted is gone.
    You should try using a QList of points to store every clicked point and paint all of them.

Similar Threads

  1. How to draw arc between two points.
    By nikhil in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2011, 13:55
  2. Clear previous points when using draw(from,to)
    By huseyinkozan in forum Qwt
    Replies: 4
    Last Post: 1st April 2009, 23:11
  3. want to draw points in QGraphicsScene
    By ntp in forum Qt Programming
    Replies: 2
    Last Post: 10th April 2008, 18:14
  4. How to draw some points and lines?
    By luffy27 in forum Qt Programming
    Replies: 1
    Last Post: 24th November 2006, 16:47

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
  •  
Qt is a trademark of The Qt Company.