Results 1 to 3 of 3

Thread: Animatin a custom property

  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 Animatin a custom property

    Hi! I created a property in a subclass of QGraphicsProxyWidget this way:

    Qt Code:
    1. class SlideshowItemProxyWidget : public QGraphicsProxyWidget {
    2. Q_OBJECT
    3. Q_PROPERTY(QPointF center READ center WRITE setCenter)
    4. public:
    5. SlideshowItemProxyWidget(QGraphicsItem* parent);
    6. QPointF center();
    7. void setCenter(QPointF point);
    8. };
    9.  
    10. SlideshowItemProxyWidget::SlideshowItemProxyWidget(QGraphicsItem* parent) : QGraphicsProxyWidget(parent) {
    11. }
    12.  
    13. QPointF SlideshowItemProxyWidget::center() {
    14. return QPointF(pos().x() + size().width()/2, pos().y() + size().height()/2);
    15. }
    16.  
    17. void SlideshowItemProxyWidget::setCenter(QPointF point) {
    18. setPos(point.x() - size().width(), point.y() - size().height());
    19. }
    To copy to clipboard, switch view to plain text mode 

    It seems to work correctly when called. The problem is that it seems it's not called when creating an animation with QPropertyAnimation this way:

    Qt Code:
    1. imageItem = (SlideshowItemProxyWidget*)this->addWidget(labelPixmap);
    2. QPropertyAnimation* animNewImage = new QPropertyAnimation(imageItem, "center");
    3. animNewImage->setDuration(IMAGE_TRANSITION_INTERVAL);
    4. animNewImage->setStartValue(QPointF(1000, 0));
    5. animNewImage->setEndValue(view->mapToScene(QPointF((view->width() - imageItem->boundingRect().width()*currentScale)/2,
    6. (view->height() - imageItem->boundingRect().height()*currentScale)/2).toPoint()));
    7. connect(animNewImage, SIGNAL(finished()), this, SLOT(adaptForNewImage()));
    8. animNewImage->start(QPropertyAnimation::DeleteWhenStopped);
    To copy to clipboard, switch view to plain text mode 

    I placed a breakpoint in the method and it doesn't stop there in this case. Nothing happens indeed. Any idea why?
    Thanks for any help!

  2. #2
    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: Animatin a custom property

    What is the class of the object represented by "this" in the second snippet? Are you sure its addWidget() method will create a SlideshowItemProxyWidget and not a QGraphicsProxyWidget? A C cast like yours will suceed of course but will not transform a QGraphicsProxyWidget into SlideshowItemProxyWidget. The first method from SlideshowItemProxyWidget you call on it will crash your application. The "center" property will not work either of course. Virtual methods will be called from QGraphicsProxyWidget and not SlideshowItemProxyWidget.

  3. The following user says thank you to wysota for this useful post:

    Luc4 (13th April 2010)

  4. #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: Animatin a custom property

    You're right! I solved creating the SlideshowItemProxyWidget and then adding it to the scene using the addItem. Thanks for the help!

Similar Threads

  1. Linker error when creating custom Property Browser components
    By stefanadelbert in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2010, 03:50
  2. Replies: 4
    Last Post: 5th March 2010, 14:20
  3. Replies: 6
    Last Post: 14th April 2007, 07:59
  4. Replies: 5
    Last Post: 16th May 2006, 20:38
  5. custom plugin designer property with out a variable?
    By high_flyer in forum Qt Programming
    Replies: 1
    Last Post: 15th March 2006, 19:11

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.