Results 1 to 3 of 3

Thread: Create animated gradient arrow

  1. #1
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

    Default Create animated gradient arrow

    Hi,
    I want to create animated gradient arrow. I used the following code, but it does not show animated gradient.

    Qt Code:
    1. Canvas {
    2. id: arrowDown
    3. width: parent.height/3
    4. height: width
    5. antialiasing: true
    6. anchors.centerIn: parent
    7.  
    8. property color secondaryColor: "blue"
    9.  
    10. property real centerWidth: width / 2
    11. property real centerHeight: height / 2
    12. property real radius: (Math.min(arrowDown.width, arrowDown.height)*2) / (2*Math.PI)
    13.  
    14. onSecondaryColorChanged: requestPaint()
    15. onVisibleChanged: requestPaint()
    16.  
    17. onPaint: {
    18. var ctx = getContext("2d");
    19. ctx.save();
    20. ctx.clearRect(0, 0, arrowDown.width, arrowDown.height);
    21. ctx.beginPath();
    22.  
    23. ctx.lineWidth = 8;
    24. ctx.moveTo(arrowDown.centerWidth,
    25. arrowDown.centerHeight-arrowDown.radius/2);
    26. ctx.strokeStyle = secondaryColor
    27.  
    28. ctx.lineTo(arrowDown.centerWidth,
    29. arrowDown.centerHeight+arrowDown.radius/2);
    30.  
    31. ctx.lineTo(arrowDown.centerWidth+arrowDown.centerWidth/4,
    32. arrowDown.centerHeight+arrowDown.radius/4);
    33.  
    34. ctx.moveTo(arrowDown.centerWidth,
    35. arrowDown.centerHeight+arrowDown.radius/2);
    36. ctx.lineTo(arrowDown.centerWidth-arrowDown.centerWidth/4,
    37. arrowDown.centerHeight+arrowDown.radius/4);
    38.  
    39. var gradient = ctx.createLinearGradient(0, 0, 100, 100);
    40. gradient.addColorStop(0.3, Qt.rgba(1, 0, 0, 1));
    41. gradient.addColorStop(0.7, "white");
    42.  
    43. ctx.stroke();
    44. ctx.restore();
    45. }
    46.  
    47. Timer {
    48. interval: 200
    49. repeat: true
    50. running: true
    51.  
    52. onTriggered: {
    53. ???
    54. arrowDown.requestPaint()
    55. }
    56. }
    57. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by neda; 9th November 2016 at 12:10.

  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: Create animated gradient arrow

    Which value do you want to be animated?
    Where is your animation setup?

    Cheers,
    _

  3. #3
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Create animated gradient arrow

    My decision changed. An array of arrows come from the top down (such as 3 arrow) and coming down arrows disappeared and all have gradient background.

    All the above steps are in a loop.

Similar Threads

  1. Path of Gradient
    By Wong in forum Qt Programming
    Replies: 6
    Last Post: 20th January 2013, 08:40
  2. How to create an animated GIF file with some BMP files?
    By accordionist in forum General Programming
    Replies: 2
    Last Post: 30th December 2010, 12:25
  3. Add a QGraphicsTextItem with a gradient
    By harmodrew in forum Newbie
    Replies: 5
    Last Post: 16th November 2010, 17:50
  4. Create gradient and shadow on text?
    By Kevin Hoang in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2010, 08:41
  5. Replies: 3
    Last Post: 17th July 2006, 17:57

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.