Results 1 to 3 of 3

Thread: how to keep the last elements of QPainterPath

  1. #1
    Join Date
    Jul 2015
    Posts
    52
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default how to keep the last elements of QPainterPath

    I am drawing with QPainterPath at regular times. ALl in all, I have a slot called every 100 ms that updates the position of the tip adding a new point to the path. How could I keep the last 1000 points and discard and free the memory of the older ones?

  2. #2
    Join Date
    Jul 2015
    Posts
    52
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to keep the last elements of QPainterPath

    No go with this one?

  3. #3
    Join Date
    Jul 2015
    Posts
    52
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to keep the last elements of QPainterPath

    The only way I've thought of achieving this is by obtaining the path and modifying all its items. Something like:

    Qt Code:
    1. QPainterPath p = item->path();
    2. for(int i = 0; i < p.elementCount()-1; i++)
    3. {
    4. auto e = p.elementAt(i+1);
    5. p.setElementPositionAt(i, e.x(), e.y());
    6. }
    7. p.moveTo(newpoint);
    8. item->setPath(p);
    To copy to clipboard, switch view to plain text mode 

    But it's kind of lame to do it like this. If only there was the possibility of deleting the first or last item we could do it too.

    Since I haven't found any documentation on how to do this and a few posts asking similar things without answer I'm considering building the path myself by storing a vector of lines, but i guess that would be costly too. Any help is appreciated. Is there a way to access the internal vector of the path?

  4. The following user says thank you to quimnuss for this useful post:

    nilot (6th February 2017)

Similar Threads

  1. QPainterPath
    By Karl123 in forum Newbie
    Replies: 2
    Last Post: 16th June 2013, 17:26
  2. QPainterPath -
    By aguleo in forum Newbie
    Replies: 4
    Last Post: 17th February 2013, 17:47
  3. Problem with QPainterPath
    By kaktus123 in forum Qt Programming
    Replies: 0
    Last Post: 7th August 2012, 13:10
  4. QPainterPath::quadTo(...) calls QPainterPath::cubicTo(...) ?
    By brucelamond in forum Qt Programming
    Replies: 0
    Last Post: 29th April 2011, 00:30
  5. QPainterPath and scale()
    By edwardc in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2010, 11:03

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.