Results 1 to 11 of 11

Thread: How to change the SIZE of a graphicsItem during animation(QGraphicsItemAnimation).

  1. #1
    Join Date
    Aug 2011
    Location
    Pune, India
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default How to change the SIZE of a graphicsItem during animation(QGraphicsItemAnimation).

    HI,
    I want to change the SIZE of a graphicsItem (eclipse) during its animation using QGraphicsItemAnimation.

    The Eclipse is drawn from the below code:
    ---
    Qt Code:
    1. QRectF Node::boundingRect() const
    2. {
    3. qreal adjust = 2;
    4. return QRectF( -10 - adjust, -10 - adjust,
    5. 23 + adjust, 23 + adjust);
    6. }
    7.  
    8. void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
    9. {
    10. painter->setBrush(Qt::red);
    11. painter->setPen(QPen(Qt::red, 0));
    12. painter->drawEllipse(-10, -10, 20, 20);
    13. }
    To copy to clipboard, switch view to plain text mode 
    ---
    Eclipse(Node) of above size got created.

    Now in QGraphicsItemAnimation i want to change it's size to (-20,-20,40,40).

    Could you please help me in changing the size of the eclipse. what functions can be used.

    thanks,
    Akash
    Last edited by wysota; 29th August 2011 at 17:47. Reason: missing [code] tags

  2. #2
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: How to change the SIZE of a graphicsItem during animation(QGraphicsItemAnimation)

    just use member variables instead of hardcoded values. Write a setter method to set these variables whenever you need. Remember to call prepareGeometryChange() before changing these variables in the setter method.
    Don't write a post just to thank someone, use "Thanks" button.

  3. #3
    Join Date
    Aug 2011
    Location
    Pune, India
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to change the SIZE of a graphicsItem during animation(QGraphicsItemAnimation)

    Hi,

    Thanks for the suggestion, partial problem is resolved.
    I have another query regarding this.
    I have n no. of nodes(eclipses) created from the same boundingrect and paint function, but these nodes(eclipses) are placed at different points in a scene.

    Q. i want to change the size of all nodes(eclipses) simultaneously (parallel animation) by some random values +/- their width and height.
    is there any way to do paralel animation in QGraphicsItemAnimation.

    Thanks in advance,
    Akash
    Last edited by akash; 29th August 2011 at 15:21. Reason: reformatted to look better

  4. #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: How to change the SIZE of a graphicsItem during animation(QGraphicsItemAnimation)

    Why don't you use the animation framework instead of QGraphicsItemAnimation?
    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.


  5. #5
    Join Date
    Aug 2011
    Location
    Pune, India
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to change the SIZE of a graphicsItem during animation(QGraphicsItemAnimation)

    Hi,
    I have used QParallelAnimationGroup for parallel animation of n buttons. But i think QParallelAnimationGroup only supports QWIdgets and not graphicsitems. This was the reason i switched to QGraphicsItemAnimation to animate GraphicsItems.

    Please let me know if there is any way to do parallelanimation for graphicsitems in QParallelAnimation/QGraphicsItemAnimation.
    Or can we convert GraphicsItem to QWidget and use QParallelAnimationGroup to animate.

    Correct me if i m leading in wrong direction.

    Thanks,
    Akash

  6. #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: How to change the SIZE of a graphicsItem during animation(QGraphicsItemAnimation)

    Quote Originally Posted by akash View Post
    I have used QParallelAnimationGroup for parallel animation of n buttons. But i think QParallelAnimationGroup only supports QWIdgets and not graphicsitems.
    No, that's not true. Have a look at the "animated tiles" demo.
    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.


  7. #7
    Join Date
    Aug 2011
    Location
    Pune, India
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to change the SIZE of a graphicsItem during animation(QGraphicsItemAnimation)

    Hi,

    I have gone through the animated tiles example, thanks for the suggestion.
    In this example the animation is applied on pos of a pixmap.
    Now, if i want to change the size of this pixmap through animation, what QtProperty should be taken care of.

    Below is the code change that i did to change the size of pixmap.

    class Pixmap : public QObject, public QGraphicsPixmapItem
    {
    Q_OBJECT
    // Q_PROPERTY(QPointF pos READ pos WRITE setPos)
    Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)

    * i replaced pos with geometry.

    After changing some code, below error occured.

    Error: geometry/setGeometry not declared in scope.

    My understanding:
    setGeometry is not used in right place/not the right property that can change the size of pixmap/graphicitem.

    Could you please let me know what code and where should i change the code to get the proper output.

    Solution to this problem may solve my entire problem.


    Thanks,
    Last edited by akash; 31st August 2011 at 07:14.

  8. #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: How to change the SIZE of a graphicsItem during animation(QGraphicsItemAnimation)

    QGraphicsPixmapItem doesn't have "geometry" and "setGeometry" methods. You'll have to implement them if you want to have such a property. However I don't see how this would work since the pixmap is of fixed size. Maybe you want to scale and not resize the item? If so, then it will be easiest to use QGraphicsScale which already has appropriate properties defined.
    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. #9
    Join Date
    Aug 2011
    Location
    Pune, India
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to change the SIZE of a graphicsItem during animation(QGraphicsItemAnimation)

    Hi,
    Here is the main problem that i m trying to resolve.

    Problem:
    In a graph i have nodes and edges. Initially the size of nodes and edges are fixed. I have to change the size of nodes as per some random data from a file or from an array. The size of all nodes should get change simultaneously along with the size/length of edges connecting them to give proper animation effect.

    To Solve this problem i used "elasticnodes" example and convert this moving node to static graph. i removed their calculate force function so that nodes should not move automatically after draging any node.

    Currently i have nodes and edges well connected to each other, with the help of a mouse i can change the positon of nodes, connections dont get distorted after changing the positions and gives elastic effects.

    I tried scaleing a node and it was working fine, but connected edges were not changing their length and connections were distorted. so, i planned to change the size of nodes and shift their positions to give proper effect of scaling and as per my understanding connected edges should/will change their length as per the node positions.

    Road Blocks:
    1. Unable to change the size of nodes.
    2. Scaling the nodes distorts the connections.
    3. Unable to do all above simultaneously/ parallelanimation on graphicitems.

    Please guide me on this, so that i can step in right direction and reslove this issue.

    thanks in advance for you attention,

    ~Akash

  10. #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: How to change the SIZE of a graphicsItem during animation(QGraphicsItemAnimation)

    Then why are you using pixmap items?

    Here is a small demo:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class Item : public QGraphicsObject {
    4. Q_OBJECT
    5. Q_PROPERTY(qreal size READ size WRITE setSize)
    6. public:
    7. Item(QGraphicsItem *parent = 0) : QGraphicsObject(parent) {
    8. setSize(10.0);
    9. }
    10. void setSize(qreal s) {
    11. if(m_rect.width()==s) return;
    12. m_rect = QRectF(-s/2,-s/2, s, s);
    13. prepareGeometryChange();
    14. }
    15. qreal size() const { return m_rect.width(); }
    16. QRectF boundingRect() const {
    17. return m_rect;
    18. }
    19. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) {
    20. painter->setBrush(Qt::red);
    21. painter->drawEllipse(boundingRect());
    22. }
    23. private:
    24. QRectF m_rect;
    25. };
    26.  
    27. #include "main.moc"
    28.  
    29. int main(int argc, char **argv){
    30. QApplication app(argc, argv);
    31. qsrand(QDateTime::currentDateTime().toTime_t());
    32. QParallelAnimationGroup *animGrp = new QParallelAnimationGroup(&scene);
    33. animGrp->setLoopCount(-1);
    34. for(int i=0;i<10;++i) {
    35. Item *item = new Item;
    36. scene.addItem(item);
    37. item->setPos(qrand() % 400, qrand()%400);
    38. QPropertyAnimation *anim = new QPropertyAnimation(item, "size", animGrp);
    39. animGrp->addAnimation(anim);
    40. anim->setStartValue(qrand()%30);
    41. anim->setEndValue(40+qrand()%50);
    42. anim->setEasingCurve(QEasingCurve::Type(qrand()%41));
    43. anim->setDuration(250*(qrand()%10));
    44. }
    45.  
    46. view.setScene(&scene);
    47. view.show();
    48. view.setRenderHint(QPainter::Antialiasing);
    49. animGrp->start();
    50. return app.exec();
    51. }
    To copy to clipboard, switch view to plain text mode 
    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.


  11. #11
    Join Date
    Aug 2011
    Location
    Pune, India
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to change the SIZE of a graphicsItem during animation(QGraphicsItemAnimation)

    Hi,
    Thanks for the pointers.
    Problem is resolved.
    I used pixmap because i was trying to get solution of problem by changing the properties of a graphicsitem,and was trying to learn by doing hit and trial.
    once again thanks for your help.


    ~akash

Similar Threads

  1. QGraphicsObject color change animation
    By mvbhavsar in forum Newbie
    Replies: 8
    Last Post: 30th August 2011, 13:34
  2. Had a Conceptual doubts on QGraphicsItemAnimation ?
    By punitk in forum Qt Programming
    Replies: 3
    Last Post: 7th October 2010, 11:23
  3. QGraphicsItemAnimation and QTimeLine
    By babu198649 in forum Newbie
    Replies: 13
    Last Post: 31st December 2007, 11:34
  4. change picture size
    By raphaelf in forum Newbie
    Replies: 1
    Last Post: 27th November 2006, 18:15
  5. change font size and button size of QMessageBox
    By nass in forum Qt Programming
    Replies: 6
    Last Post: 13th September 2006, 19:16

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.