Results 1 to 4 of 4

Thread: What is the best way to create my own animated canvas item ?

  1. #1
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default What is the best way to create my own animated canvas item ?

    Hi everybody,

    I need to play animation, just as QCanvasSprite does, but the way this class works does not feet to my need.

    I need to play the animation foreward and backward and the animation must stop once the last item (if playing foreward) or the first item (if playing backward) has been drawn.

    So here are my questions :
    * should I subclass the QCanvasSprite to respond to my need ?
    * is it possible to subclass the QCanvasSprite class ?if it is, how must I do ?
    * if it is not possible to subclass does someone could tell me about its experience ?

    Thanks in advance for your 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: What is the best way to create my own animated canvas item ?

    I think you should subclass QCanvasSprite and reimplement advance(). In your reimplementation you should check if you are currently on the last/first frame and if not, increase/decrease the frame number. Later you must call the base implementation from QCanvasItem to do the rest of the job (don't call the implementation from QCanvasSprite!).

    I don't think default canvas sprites provide backward animation, so you have to implement that yourself, for example by reimplementing setFrameAnimation() or by defining your own method.

  3. #3
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: What is the best way to create my own animated canvas item ?

    ok, I tryed with the following code

    Qt Code:
    1. void CMySprite::advance(int phase)
    2. {
    3. if( frame() != 0 )
    4. setFrame(frame() - 1);
    5.  
    6. QCanvasItem::advance(phase);
    7. }
    To copy to clipboard, switch view to plain text mode 

    ... it works backward and stops when the first image is reached.

    So I would like to reimplement setFrameAnimation() ... but how is it possible to modify the enum FrameAnimationType in order to add my own animation types ? Should I declare my own enum with cycle, oscillation and my own values or is there another way to do it ?

    About advance(), I also tryed without calling the base class method and it works as well, is it really necessary to call the base class method ?

    thanks in advance

  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: What is the best way to create my own animated canvas item ?

    Quote Originally Posted by yellowmat
    So I would like to reimplement setFrameAnimation() ... but how is it possible to modify the enum FrameAnimationType in order to add my own animation types ? Should I declare my own enum with cycle, oscillation and my own values or is there another way to do it ?
    Maybe you could use one of existing types? If not, you can always add a new method to the class.

    About advance(), I also tryed without calling the base class method and it works as well, is it really necessary to call the base class method ?
    The base class implementation moves the object. If your object is not to be moved automatically, you can skip the base call, but there is nothing wrong in making it, so I'd leave it as it is.

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

    yellowmat (18th July 2006)

Similar Threads

  1. When is the best time to delete a QCanvasItem
    By irudkin in forum Qt Programming
    Replies: 12
    Last Post: 8th March 2007, 21:28
  2. Setting focus on Canvas
    By Kapil in forum Qt Programming
    Replies: 10
    Last Post: 17th May 2006, 12:55
  3. how change the QListBox item position by pixel
    By roy_skyx in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 01:34

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.