Results 1 to 3 of 3

Thread: change color on dragging curve

  1. #1
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default change color on dragging curve

    I can put a bezier curve on a MouseArea on mouseclick. I can even drag and drop it. But how can I change the color of the curve while dragging it? My code:

    Qt Code:
    1. Item {
    2. Path {
    3. id: mycurve
    4. startX: -132; startY: -12
    5. PathCurve { x: -138; y: -14 }
    6. PathCurve { x: -140; y: -20 }
    7. PathCurve { x: -146; y: -22 }
    8. }
    9. Rectangle {
    10. id: rect
    11. width: 2
    12. height: 2
    13. color: "black"
    14. border.color: "black"
    15.  
    16.  
    17. MouseArea {
    18. anchors.fill: parent
    19. acceptedButtons: Qt.LeftButton | Qt.RightButton
    20. onPressed: {mycurve.color = "red";}//what should I do here?
    21. onReleased: {mycurve.color = "black";}//what should I do here?
    22. onPositionChanged: {
    23. if (mouse.buttons & Qt.LeftButton) {
    24. mycurve.x -= (x - mouse.x); mycurve.y = (y - mouse.y); ;
    25. }
    26.  
    27. }
    28. }
    29. PathView {
    30. id: pathView1;
    31. x: 158
    32. width: 708
    33. model: 300;
    34. path: mycurve
    35. delegate: Rectangle {
    36. id: dot;
    37. width: 1; height: 1;
    38. color: "black"
    39. ColorAnimation on color { to: "red"; duration: 0 }//my own attempt
    40. }
    41. }
    42. }
    43. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: change color on dragging curve

    mycurve is currently only a standard Path, it doesn't have a color property.

    Add one and use it in the delegate or add the property to any other object that both the delegate and the mouse are have access to.

    Cheers,
    _

  3. #3
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: change color on dragging curve - SOLVED

    Solved. Thank you.

Similar Threads

  1. Replies: 3
    Last Post: 3rd February 2014, 18:04
  2. How to Change Curve Color when it out of scale
    By baoxuefei771 in forum Qwt
    Replies: 12
    Last Post: 13th August 2013, 05:30
  3. Replies: 11
    Last Post: 5th February 2013, 02:10
  4. Dynamically change existing curve color
    By missoni in forum Qwt
    Replies: 2
    Last Post: 19th June 2012, 12:32
  5. Replies: 3
    Last Post: 22nd January 2010, 17: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.