Results 1 to 2 of 2

Thread: QPropertyAnimations in Qt Script

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2008
    Posts
    45
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QPropertyAnimations in Qt Script

    So I can't get this to work. The xScale factor should be animated. It works in C++ but not QtScript. You will need qt-master and the latest bindings generator (4.6 branch)
    The only message I get is "QPropertyAnimation::updateState: Changing state of an animation without target"

    http://pastebin.com/m51cee344
    or
    Qt Code:
    1. function GraphicsItemPropertyProxy (item, parent)
    2. {
    3. //QObject.call(parent);
    4. this.item = item;
    5. this._xScale = 1;
    6. }
    7.  
    8. GraphicsItemPropertyProxy.prototype = new QObject();
    9. GraphicsItemPropertyProxy.__defineGetter__("xScale", function() { return this._xScale; });
    10. GraphicsItemPropertyProxy.__defineSetter__("xScale",
    11. function(v) {
    12. print("setting xScale to", v);
    13. this._xScale = v;
    14. this.updateTransform();
    15. return v;
    16. }
    17. );
    18. GraphicsItemPropertyProxy.prototype.updateTransform=function() {
    19. print("updateTransform()");
    20. this.item.setTransform(new QTransform().translate(0,0)
    21. .rotate(0, Qt.ZAxis)
    22. .rotate(0, Qt.YAxis)
    23. .rotate(0, Qt.XAxis)
    24. .scale(this._xScale, 5)
    25. .translate(0, 0));
    26. }
    27.  
    28. function AffineTextItem(text, font, brush, parent)
    29. {
    30. QGraphicsItem.call(this, parent);
    31. var fm = new QFontMetrics(font);
    32.  
    33. this.path = new QPainterPath();
    34. this.brush=brush;
    35. this.path.addText(0,fm.ascent(), this.font, text);
    36. this.br = fm.boundingRect(text).adjusted(0,0,0, fm.ascent());
    37. this.boundingRect = function() { return this.br; };
    38. }
    39.  
    40. AffineTextItem.prototype = new QGraphicsItem();
    41.  
    42. AffineTextItem.prototype.paint = function (painter, options, widget)
    43. {
    44. if (this.opacity()==0)
    45. return;
    46. painter.fillPath(this.path, this.brush);
    47. }
    48.  
    49.  
    50. var scene = new QGraphicsScene();
    51. scene.setSceneRect(0,0, 900, 500);
    52.  
    53.  
    54. var item = new AffineTextItem("this is text", new QFont("Arial", 25), new QColor(255,0,0));
    55. item.setOpacity(0.75);
    56. scene.addItem(item);
    57. var proxy = new GraphicsItemPropertyProxy(item);
    58. var animX = new QPropertyAnimation(proxy, "xScale");
    59. animX.startValue = 50.0;
    60. animX.endValue = 10.0;
    61. animX.duration = 5000.0;
    62. animX.loopCount = -1;
    63.  
    64. var view = new QGraphicsView(scene);
    65. view.renderHints = (QPainter.Antialiasing | QPainter.SmoothPixmapTransform | QPainter.TextAntialiasing);
    66.  
    67. var blueGradient = new QLinearGradient (0,0,0,1080);
    68. blueGradient.setColorAt(0, new QColor(0,255,0));
    69. blueGradient.setColorAt(1, new QColor(0,0,255));
    70.  
    71. view.backgroundBrush = new QBrush(blueGradient);
    72. animX.start();
    73. view.resize(960, 540);
    74. view.show();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Apr 2008
    Posts
    45
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPropertyAnimations in Qt Script

    I am now offering $20 via PayPal for a working QtScript solution.

    To qualify, you must use the GraphicsItemPropertyProxy technique from the script (lines 1-26) and the general approach of lines 57-75.

    From what I can tell the QPropertyAnimation is not accepting the item passed in because d->target is null. It is my understanding that javascript objects are interchangeable with QObjects, so this should work.

Similar Threads

  1. Whats wrong with this script -- help needed
    By swamyonline in forum Qt Programming
    Replies: 5
    Last Post: 2nd July 2009, 13:17
  2. Qt Script
    By c_srikanth1984 in forum Qt Programming
    Replies: 3
    Last Post: 9th June 2009, 10:35
  3. Can I include a script from script?
    By yycking in forum Qt Programming
    Replies: 1
    Last Post: 24th April 2009, 03:01
  4. Testing app with Qt Script
    By Angelo Moriconi in forum Qt Programming
    Replies: 5
    Last Post: 23rd October 2007, 08:20
  5. How to use PERL script in Qt
    By joseph in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2007, 21: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
  •  
Qt is a trademark of The Qt Company.