Results 1 to 20 of 22

Thread: QPropertyAnimation+QGraphicsItem : use 25% of the CPU

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2010
    Posts
    95
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question QPropertyAnimation+QGraphicsItem : use 25% of the CPU

    Hi,

    I use a QPropertyAnimation to animate a QGraphicsItem but when the animation start it use 25% of the CPU (and I need this CPU for other operations).

    All I do is an "update" on the item when the property is changed... so it request an item redraw !

    How can I reduce this ?

    Thanks

  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: QPropertyAnimation+QGraphicsItem : use 25% of the CPU

    Show us your item implementation, in particular its boundingRect() code.
    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.


  3. #3
    Join Date
    Oct 2010
    Posts
    95
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPropertyAnimation+QGraphicsItem : use 25% of the CPU


  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: QPropertyAnimation+QGraphicsItem : use 25% of the CPU

    We still have no idea how the boundingRect() for your item is defined. What do you set it to?
    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
    Oct 2010
    Posts
    95
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPropertyAnimation+QGraphicsItem : use 25% of the CPU

    I have not redefined the 'boundingRect' method !

  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: QPropertyAnimation+QGraphicsItem : use 25% of the CPU

    I know but you are calling setRect() somewhere which defines the bounding rect. By the way, why are you manipulating the animation in the function related to drawing your item?
    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
    Oct 2010
    Posts
    95
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPropertyAnimation+QGraphicsItem : use 25% of the CPU

    Yes,

    I call : setRect(0, 0, 90, 90); in the "initializeNode()" method.

    By the way, why are you manipulating the animation in the function related to drawing your item?
    Because, when the item is selected I want to animate a "circle" around the item... a simple color transition... that will highlight the selected item.

  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: QPropertyAnimation+QGraphicsItem : use 25% of the CPU

    Quote Originally Posted by pl01 View Post
    I call : setRect(0, 0, 90, 90); in the "initializeNode()" method.
    Try enabling cache for your items. However this will surely break your already broken animation code. I wouldn't expect miracles performance wise if you are changing the highlight color constantly. Maybe making the highlight a separate item would help more.


    Because, when the item is selected I want to animate a "circle" around the item... a simple color transition... that will highlight the selected item.
    paint() routine is for painting, not for starting animations. Manipulate the animation when the selection value changes. And set the loop count to infinite instead of manually checking the state of the animation every frame and restarting it when it finishes its course.
    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
    Oct 2010
    Posts
    95
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPropertyAnimation+QGraphicsItem : use 25% of the CPU

    Thanks,

    1) I used setCacheMode(QGraphicsItem:eviceCoordinateCache); for caching... Notice I also need anti-aliasing !
    2) Sure, I can start the animation somewhere else... but it would'nt change anything to performance ! (I have just try of course) ;-)

  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: QPropertyAnimation+QGraphicsItem : use 25% of the CPU

    Quote Originally Posted by pl01 View Post
    1) I used setCacheMode(QGraphicsItem:eviceCoordinateCache); for caching... Notice I also need anti-aliasing !
    I don't see how anti-aliasing is relevant here. I would rather use ItemCoordinateCache.

    2) Sure, I can start the animation somewhere else... but it would'nt change anything to performance ! (I have just try of course) ;-)
    If you change the item every frame, then caching only makes your app slower since it has to be regenerated again and again. If you move the animation outside your item then at least the item itself can be cached properly and will not execute your quite complex code on each frame of the animation. All this does not change the fact that putting animation controlling code into a paint routine is simply wrong.
    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.


Similar Threads

  1. QParallelAnimationGroup and QPropertyAnimation
    By nudels in forum Qt Programming
    Replies: 3
    Last Post: 26th January 2012, 11:17
  2. QPropertyAnimation doesnt do anything
    By superpacko in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2011, 16:04
  3. QPropertyAnimation dynamic end value is this possible?
    By GuusDavidson in forum Qt Programming
    Replies: 1
    Last Post: 11th March 2011, 12:09
  4. Using QPropertyAnimation with QGraphicsPixmapItem
    By Luc4 in forum Qt Programming
    Replies: 8
    Last Post: 29th March 2010, 09:47
  5. Replies: 1
    Last Post: 8th January 2010, 12:21

Tags for this Thread

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.