Results 1 to 11 of 11

Thread: Removing last Painted point

  1. #1
    Join Date
    Jun 2013
    Posts
    58
    Thanks
    26
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Arrow Removing last Painted point

    Good Day

    I store points in an array (points taken from position of mouse click)

    In my paintEvent I draw points from array
    Qt Code:
    1. painter.setPen(myPen);
    2. foreach(tempMark, myPoints)
    3. {
    4. painter.drawEllipse(tempMark, 2, 2);
    5. }
    To copy to clipboard, switch view to plain text mode 

    I created an UNDO Button that deletes the last point from array
    I tested it, by writing points to file, That point is deleted

    But my paintEvent still displays that point while I'm creating new points
    (note all points must be displayed at all times during the run of the program)
    If I click Undo, it should Remove only the last point
    (which it does from the array - Button is working) But the point is still displayed on the screen

    PushButton_Undo
    Qt Code:
    1. myPoints.removeLast();
    2. this->repaint(); //-> probably this->repaint() not working! maybe
    To copy to clipboard, switch view to plain text mode 

    Do I add something to the paint Event?
    Any Ideas?

    Many Thanks
    Last edited by ebsaith; 28th June 2013 at 12:01. Reason: updated contents

  2. #2
    Join Date
    Aug 2009
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Removing last Painted point

    Hi, i think that PushButton_Undo not call. Can add to you code

    Qt Code:
    1. qDebug() << Q_FUNC_INFO;
    To copy to clipboard, switch view to plain text mode 

    and view console log.

  3. The following user says thank you to ecspertiza for this useful post:

    ebsaith (1st July 2013)

  4. #3
    Join Date
    Jun 2013
    Posts
    58
    Thanks
    26
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Question Re: Removing last Painted point

    The push Button is being called, Since the array is being updated
    The problem is the paint function not rendering the updated array.

    Ideas welcome

    Thanks

  5. #4
    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: Removing last Painted point

    Add the qDebug() call to the paint event and see if it is called or not. By the way, use update() instead of repaint().
    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.


  6. The following user says thank you to wysota for this useful post:

    ebsaith (1st July 2013)

  7. #5
    Join Date
    Jun 2013
    Posts
    58
    Thanks
    26
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Removing last Painted point

    added update();

    Added the above qDebug line of code, program compiles
    though im not sure what i'm supposed to look for/where/...?
    some guidance please

    Kind Regards

  8. #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: Removing last Painted point

    You should observe whether calling your undo results in the debug statement you put in the paint event being printed.
    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.


  9. The following user says thank you to wysota for this useful post:

    ebsaith (1st July 2013)

  10. #7
    Join Date
    Jun 2013
    Posts
    58
    Thanks
    26
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Removing last Painted point

    Thanks for your help...

    Please inform me,
    How would I go about creating a function that can remove ANY point from screen.

    Example: In running program, user creates 7+ points
    User is able to click one of the previous points to remove it

    Note: all points are stored in an array
    How would I test The mouse position against array to delete point

    Ideas Welcome
    Kind Regards

  11. #8
    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: Removing last Painted point

    Use mouse events to determine which of the stored point the user clicked on, remove that point from the stored list, redraw.
    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.


  12. The following user says thank you to wysota for this useful post:

    ebsaith (2nd July 2013)

  13. #9
    Join Date
    Jun 2013
    Posts
    58
    Thanks
    26
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Question Re: Removing last Painted point

    My program crashes when I try removing point
    //using popUpMenu to remove point

    Here is my code:
    Qt Code:
    1. void LabelClass::RemovePoint()
    2. {
    3. QList<int> lengthArray;
    4. int min = 0;
    5. int indexMin = 0
    6. int tempLength = 0;
    7.  
    8. int index = 0;
    9. while (index < myArrayCounter)
    10. {
    11. //Using Distance Formula to determine nearest point
    12. //x1 and y1 are coordinates of mouse position at the time of click on popUpMenu
    13. tempLength = sqrt(pow((x1 - myArray[index]),2) + pow((y1 - myArray[index+1]), 2));
    14. lengthArray.append(tempLength);
    15.  
    16. //[I]Find Smallest[/I]
    17. min = lengthArray[index];
    18. if (lengthArray[index] < minRe)
    19. {
    20. min = lengthArray[index];
    21. indexMin = index;
    22. }
    23. index += 2;
    24. //Array stored as |x|y|x|y|...
    25. }
    26. //delete x & y value & decrement counters
    27. myCounter -= 1;
    28. myArrayCounter -= 2;
    29. myArray.removeAt(indexMin);
    30. myArray.removeAt(indexMin);
    To copy to clipboard, switch view to plain text mode 

    I create this same algorithm per category of points (pointsA, pointsB,.. stored in differentArrays)
    compare the smallest length of each array and delete at index of that array

    Help, please
    Ideas on a more efficient algorithm, most welcome!
    Kind Regards
    Last edited by ebsaith; 2nd July 2013 at 10:05. Reason: updated contents

  14. #10
    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: Removing last Painted point

    I would use QPoint and QPoint::manhattanLength() to calculate the distance.

    Qt Code:
    1. int closestPoint(const QList<QPoint> &points, const QPoint &pt) {
    2. if(points.isEmpty()) return -1;
    3. int minIdx = 0;
    4. int minDistance = (points.at(0)-pt).manhattanLength();
    5. for(int i=1;i<points.size();++i) {
    6. int dist = (points.at(i)-pt).manhattanLength();
    7. if(dist < minDistance) { minIdx = i; minDistance = dist; }
    8. }
    9. // cutoff: if(minDistance > 10) return -1;
    10. return minIdx;
    11. }
    To copy to clipboard, switch view to plain text mode 

    And then:

    Qt Code:
    1. QList<QPoint> points;
    2. QPoint clickedPoint;
    3. int closest = closestPoint(points, clickedPoint);
    4. if(closest >=0) points.removeAt(closest);
    To copy to clipboard, switch view to plain text mode 

    You'll probably want some cutoff on the distance not to remove points that are quite far away from the destination but are still closer than all other points.
    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.


  15. The following user says thank you to wysota for this useful post:

    ebsaith (2nd July 2013)

  16. #11
    Join Date
    Jun 2013
    Posts
    58
    Thanks
    26
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Removing last Painted point

    Yes, Will try it -> looks much more efficient

    Kind Regards

Similar Threads

  1. Replies: 3
    Last Post: 21st June 2011, 20:37
  2. QDialogButtonBox text not painted
    By kshi in forum Qt Programming
    Replies: 0
    Last Post: 8th January 2011, 01:41
  3. Replies: 1
    Last Post: 3rd December 2009, 15:23
  4. display a plot point by point
    By oswalidos in forum Newbie
    Replies: 32
    Last Post: 13th March 2009, 16:37
  5. how to paint scene point by point
    By elessaar in forum Qt Programming
    Replies: 8
    Last Post: 4th September 2008, 21:00

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.