Results 1 to 1 of 1

Thread: Adjusting QLineF points AFTER it has been drawn

  1. #1
    Join Date
    Nov 2016
    Posts
    2
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android

    Default Adjusting QLineF points AFTER it has been drawn

    So I am drawing a QLineF based on the angle of a QDial, and I need to adjust the position of the points on the line periodically after it has been drawn in the QGraphicsScene. Basically I need to track the angle of the QDial with the line, but once the line is drawn, I need for the line to begin to move towards the center of the screen. as it stands right now, I just keep drawing the same line over top itself.

    Here is how I'm getting the points

    Qt Code:
    1. void addNewPoint( int qdialAngle ){
    2. double oldX = m_sceneCenter;
    3. double oldY = m_sceneCenter;
    4. double newX = oldX + qCos(qDegreesToRadians(range)) * m_sceneRadius;
    5. double newY = oldY + qCos(qDegreesToRadians(range)) * m_sceneRadius;
    6. QPointF pt(newX, newY);
    7. m_historyPoint_list.append(pt);
    8. m_historyPoint_count++;
    9.  
    10. switch(m_historyPoint_count){
    11. case 1:
    12. m_historyPoint_A = pt;
    13. break;
    14. case 2:
    15. m_historyPoint_B = pt;
    16. m_historyPoint_count = 0;
    17. break;
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

    And here is how I'm drawing the line from those points.

    Qt Code:
    1. void drawPathLine(){
    2. m_HistoryLine = QLineF(m_historyPoint_A, m_historyPoint_B);
    3. QPen linePen(Qt::green, Qt::SolidLine);
    4. linePen.setWidth(2);
    5.  
    6. m_GraphicsScene->addLine(m_HisoryLine, linePen);
    7. }
    To copy to clipboard, switch view to plain text mode 
    This all works fine, I just don't know how to adjust the points on the line afterwards.

    If I scale the QGraphicsScene slowly upwards overtime, the effect works for the most part, it worked for the prototype at least, but the problem is that the line gets smaller and smaller as time progresses. QLineF doesn't seem to be able to set the flag ItemIgnoresTransformations which would have worked in this case.

    I tried to make pointers of the Points, but QLineF didn't accept pointers.

    How can adjust this line once it has been drawn in the scene?


    Here's what I'm trying:

    Qt Code:
    1. void offsetPoints(){ //called from a timer
    2. foreach(QGraphicsLineItem* line, m_line_list){
    3. QLineF adjLine = line->line();
    4. int adjLine_pt1_x = adjLine.p1.x();
    5. int adjLine_pt1_y = adjLine.p1.y();
    6. int adjLine_pt2_x = adjLine.p2.x();
    7. int adjLine_pt2_y = adjLine.p2.y();
    8.  
    9. QPointF newOffsetP1 = QPointF(getNewPoint( getBearing(adjLine_pt1_x, adjLine_pt1_y),
    10. getRange(adjLine_pt1_x, adjLine_pt1_y));
    11.  
    12. QPointF newOffsetP2 = QPointF(getNewPoint( getBearing(adjLine_pt2_x, adjLine_pt2_y),
    13. getRange(adjLine_pt2_x, adjLine_pt2_y));
    14.  
    15. adjLine.setP1(newOffsetP1);
    16. adjLine.setP2(newOffsetP2);
    17. line->setline(adjLine);
    18. }
    19. }
    20.  
    21. QPointF getNewPoint(double bearing, double range){
    22. double oldX = m_scene_center; //view->size().width()/2
    23. double oldY = m_scene_center;
    24.  
    25. double newX = oldX + qCos(qDegreesToRadians(bearing)) * (range - m_offsetSpeed); //m_offsetSpeed -= 0.1
    26. double newY = oldY + qSin(qDegreesToRadians(bearing)) * (range - m_offsetSpeed);
    27. QPointF newPoint = QPointF(newX, newY);
    28. return newPoint;
    29. }
    30.  
    31. double getBearing(int Xpos, int Ypos){
    32. double lat1 = m_center.x();
    33. double lon1 = m_center.y();
    34. double lat2 = Xpos;
    35. double lon2 = Ypos;
    36.  
    37. double X = qSin(lon2 - lon1) * qCos(lat2);
    38. double Y = qCos(lat1) * qSin(lat2) - qSin(lat1) * qCos(lat2) * qCos(lon2 - lon1);
    39. double bearing = (qAtan2(Y,X) * (180 / 3.14159265), 360);
    40.  
    41. if(bearing < 0)
    42. bearing += 360;
    43.  
    44. return bearing;
    45. }
    46.  
    47. double getRange(int Xpos, int Ypos){
    48. double centerX = m_center.x();
    49. double centerY = m_center.y();
    50.  
    51. double newX = centerX - Xpos;
    52. double newY = centerY - Ypos;
    53.  
    54. double distance = qPow(newX, 2) - qPow(newY,2);
    55.  
    56. double range = qSqrt( distance);
    57. return range;
    58. }
    To copy to clipboard, switch view to plain text mode 

    The lines definitely are doing something after they are drawn, but their behavior is very erratic. I feel like I'm close, maybe my math is off?

    I'm storing the points used to create the lines in my "m_historyPoint_list". My thought was that I should be able to perform these calculations on the points and then the line will "simply" update, but that didn't work because once the points are in the list, they become const points.

    Again, if anyone knows of a way that I could apply the ItemIgnoresTransformations to my lines so that as I scale my scene, the lines won't shrnk, most of this headache would go away.
    Last edited by bauervision; 8th March 2017 at 18:54.

Similar Threads

  1. Replies: 2
    Last Post: 2nd May 2012, 10:49
  2. QGraphicsItem, QLineF Precise Selection
    By prashant in forum Qt Programming
    Replies: 1
    Last Post: 29th October 2009, 11:01
  3. What's the difference? (QLineF, pos, setPoints())
    By jano_alex_es in forum Newbie
    Replies: 1
    Last Post: 28th October 2009, 11:52
  4. problem in QLinef()
    By wagmare in forum Qt Programming
    Replies: 5
    Last Post: 27th February 2009, 09:44
  5. Looking for ideas for QLineF objects
    By harakiri in forum Qt Programming
    Replies: 1
    Last Post: 29th February 2008, 11:46

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.