Results 1 to 9 of 9

Thread: Using QPropertyAnimation with QGraphicsPixmapItem

  1. #1
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Using QPropertyAnimation with QGraphicsPixmapItem

    Hi! Is it possible to use QPropertyAnimation with a QGraphicsPixmapItem? I read it is possible by creating a subclass and making it inherit from QObject as well. So, I created it and defined the property like:

    Qt Code:
    1. class MyPixmap : public QObject, public QGraphicsPixmapItem {
    2. Q_OBJECT
    3. Q_PROPERTY (qreal rotation READ rotation WRITE setRotation)
    4. ...
    To copy to clipboard, switch view to plain text mode 

    but when running the animation I get a crash. I made the same for a QGraphicsItem and it worked, but this isn't. Any idea why?
    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Using QPropertyAnimation with QGraphicsPixmapItem

    that is strange. Run a debugger and see where exactly your app crashes.

  3. #3
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Using QPropertyAnimation with QGraphicsPixmapItem

    I already tried that: it crashes when it executes the instruction:
    Qt Code:
    1. QPropertyAnimation* anim = new QPropertyAnimation(item, "rotation");
    To copy to clipboard, switch view to plain text mode 
    I checked item and it seems it's my class correctly, not a NULL pointer. Everything seems OK to me... any idea? Thanks!

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Using QPropertyAnimation with QGraphicsPixmapItem

    what does the backtrace say?

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Using QPropertyAnimation with QGraphicsPixmapItem

    Well, it must be in your definition of the class. Following works fine on my system:
    Qt Code:
    1. class MyPixmap : public QObject, public QGraphicsPixmapItem
    2. {
    3. Q_OBJECT
    4. Q_PROPERTY (qreal rotation READ rotation WRITE setRotation)
    5. };
    6.  
    7. int main(int argc, char **argv)
    8. {
    9. QApplication app(argc, argv);
    10. MyPixmap *it = new MyPixmap();
    11. QPropertyAnimation* anim = new QPropertyAnimation(it, "rotation");
    12. qWarning() << anim->propertyName();
    13. delete anim;
    14. delete it;
    15. return 0;
    16. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Using QPropertyAnimation with QGraphicsPixmapItem

    I get: undefined reference to `vtable for MyPixmap'...

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Using QPropertyAnimation with QGraphicsPixmapItem

    Well here is the full code. You have to rerun qmake:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class MyPixmap : public QObject, public QGraphicsPixmapItem
    4. {
    5. Q_OBJECT
    6. Q_PROPERTY (qreal rotation READ rotation WRITE setRotation)
    7. };
    8.  
    9. int main(int argc, char **argv)
    10. {
    11. QApplication app(argc, argv);
    12. MyPixmap *it = new MyPixmap();
    13. QPropertyAnimation* anim = new QPropertyAnimation(it, "rotation");
    14. qWarning() << anim->propertyName();
    15. delete anim;
    16. delete it;
    17. return 0;
    18. }
    19.  
    20. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  8. The following user says thank you to Lykurg for this useful post:

    Luc4 (28th March 2010)

  9. #8
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Using QPropertyAnimation with QGraphicsPixmapItem

    Yes, now its working... There must be an error in my implementation. I will try to find it. Anyway, another solution was to use a QGraphicsProxyWidget. From the point of view of the performance (of animations for instance), is there any difference between using QGraphicsPixmapItems or other types of items like QGraphicsProxyWidgets? Sometimes I wonder if it would be better to use widgets or items in QGraphicsView to play animations.
    Thanks for the information!

  10. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Using QPropertyAnimation with QGraphicsPixmapItem

    I would go for a normal item since it is not so big and heavy like a QGraphicsWidget. But if you only use a small number it does not make a big difference.

Similar Threads

  1. QGraphicsPixmapItem to QGraphicsScene
    By strateng in forum Newbie
    Replies: 5
    Last Post: 27th March 2010, 01:50
  2. Replies: 1
    Last Post: 8th January 2010, 12:21
  3. Replies: 8
    Last Post: 12th November 2009, 00:51
  4. Replies: 2
    Last Post: 11th November 2009, 08:03
  5. Scaling QGraphicsPixmapItem
    By johnsoga in forum Qt Programming
    Replies: 9
    Last Post: 7th May 2009, 17:04

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.