Page 1 of 2 12 LastLast
Results 1 to 20 of 22

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

  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.


  11. #11
    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,

    So,

    1) I have change to : ItemCoordinateCache, but nothing change :-P
    2) I have move the animation code outside the paint
    3) All I need is to partially update the item, only the "selection circle" around the item should be animated !

    Thx


    Added after 1 7 minutes:


    I have do a simple test, I have remove all the "painting" code, except the "selection circle", but it continue to use 20% of my CPU !

    There is no way to slow-down this animation ?
    Last edited by pl01; 17th June 2013 at 15:43.

  12. #12
    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 have change to : ItemCoordinateCache, but nothing change :-P
    Some things did change but not performance-wise.

    3) All I need is to partially update the item, only the "selection circle" around the item should be animated !
    There are not partial updates. Either you redraw an item or not. That's why I suggest to separate it into two items -- one that is redrawn and one that is not.

    There is no way to slow-down this animation ?
    Change the duration or modify the grade of changes (maybe it is enough to animate through 4-8 colours instead of the whole hue range?).
    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.


  13. #13
    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,

    I have also remove the "update" in the 'setSelectionHue' and.... the CPU is still at 20% !!!!!

    And no painting is done !!! It seems the problem is related to the 'QPropertyAnimation' only ?


    Added after 23 minutes:


    I have also try with a QTimer, that refresh every second.... and still 15% CPU (still without call "update()" ) !!!!

    So, it seems that the problem is somewhere in QT loops/timers/...
    Last edited by pl01; 17th June 2013 at 16:59.

  14. #14
    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

    Can you prepare a minimal compilable example reproducing the problem?
    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.


  15. #15
    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

    Hum,

    I have finaly find something really strange :-P

    If I use the default theme... everything works as expected, but with my own "style" (based on "cleanlooks") the CPU goes to 20% !!!!!!
    It seems that simply "selecting" my item use the CPU (even without all the animation stuffs) !

  16. #16
    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

    It's hard to believe since graphics items are not styled by QStyle, as far as I can tell.
    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.


  17. #17
    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 don't understand what is happening, here is my stack :

    > Qt5Guid.dll!QTextEngine::resolveAdditionalFormats( ) Line 2725 + 0x5 bytes C++
    Qt5Guid.dll!QTextEngine::itemize() Line 1450 C++
    Qt5Guid.dll!QFontMetrics::boundingRect(const QString & text="DSCS 3154") Line 674 C++
    Qt5Widgetsd.dll!QComboBoxPrivate::recomputeSizeHin t(QSize & sh={...}) Line 307 + 0x33 bytes C++
    Qt5Widgetsd.dll!QComboBox::sizeHint() Line 2336 + 0x1d bytes C++
    Qt5Widgetsd.dll!QWidgetItemV2::updateCacheIfNecess ary() Line 715 C++
    Qt5Widgetsd.dll!QWidgetItemV2::minimumSize() Line 790 C++
    Qt5Widgetsd.dll!QGridBox::minimumSize() Line 76 + 0x29 bytes C++
    Qt5Widgetsd.dll!QGridLayoutPrivate::setupLayoutDat a(int hSpacing=6, int vSpacing=6) Line 795 + 0x15 bytes C++
    Qt5Widgetsd.dll!QGridLayoutPrivate::distribute(QRe ct r={...}, int hSpacing=6, int vSpacing=6) Line 928 C++
    Qt5Widgetsd.dll!QGridLayout::setGeometry(const QRect & rect={...}) Line 1371 C++
    Qt5Widgetsd.dll!QLayoutPrivate::doResize(const QSize & r={...}) Line 592 C++
    Qt5Widgetsd.dll!QLayout::activate() Line 1094 C++
    Qt5Widgetsd.dll!QLayout::widgetEvent(QEvent * e=0x000000000436efb0) Line 639 C++
    Qt5Widgetsd.dll!QApplicationPrivate::notify_helper (QObject * receiver=0x0000000004395c90, QEvent * e=0x000000000436efb0) Line 3394 C++
    Qt5Widgetsd.dll!QApplication::notify(QObject * receiver=0x0000000004395c90, QEvent * e=0x000000000436efb0) Line 3363 + 0x1a bytes C++
    Qt5Cored.dll!QCoreApplication::notifyInternal(QObj ect * receiver=0x0000000004395c90, QEvent * event=0x000000000436efb0) Line 767 + 0x26 bytes C++
    Qt5Cored.dll!QCoreApplication::sendEvent(QObject * receiver=0x0000000004395c90, QEvent * event=0x000000000436efb0) Line 203 + 0x53 bytes C++
    Qt5Cored.dll!QCoreApplicationPrivate::sendPostedEv ents(QObject * receiver=0x0000000000000000, int event_type=0, QThreadData * data=0x0000000001b6bee0) Line 1368 + 0x17 bytes C++
    Qt5Cored.dll!QCoreApplication::sendPostedEvents(QO bject * receiver=0x0000000000000000, int event_type=0) Line 1229 C++
    Qt5Guid.dll!QWindowSystemInterface::sendWindowSyst emEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags={...}) Line 516 C++
    qwindowsd.dll!QWindowsGuiEventDispatcher::sendPost edEvents() Line 87 C++
    Qt5Cored.dll!qt_internal_proc(HWND__ * hwnd=0x0000000000340c74, unsigned int message=1025, unsigned __int64 wp=0, __int64 lp=0) Line 423 C++
    user32.dll!0000000077269bd1()
    [Frames below may be incorrect and/or missing, no symbols loaded for user32.dll]
    user32.dll!00000000772698da()
    Qt5Cored.dll!QEventDispatcherWin32:rocessEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags={...}) Line 744 C++
    qwindowsd.dll!QWindowsGuiEventDispatcher:rocessEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags={...}) Line 78 + 0x15 bytes C++
    Qt5Cored.dll!QEventLoop:rocessEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags={...}) Line 137 C++
    Qt5Cored.dll!QEventLoop::exec(QFlags<enum QEventLoop::ProcessEventsFlag> flags={...}) Line 212 + 0x3d bytes C++
    Qt5Cored.dll!QCoreApplication::exec() Line 1020 + 0x2b bytes C++
    Qt5Guid.dll!QGuiApplication::exec() Line 1184 C++
    Qt5Widgetsd.dll!QApplication::exec() Line 2674 C++

  18. #18
    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 really suggest you test your approach against a minimal example to reduce any external influences. I can see some resizing code here and nothing related to QGraphicsView.
    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.


  19. #19
    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 find the "buggy" line !

    In the custom theme, I write the following :

    void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const
    {

    case CC_ComboBox:
    if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option))
    {
    painter->save();
    ((QComboBox*)widget)->setStyleSheet("QComboBox QAbstractItemView{background-color: black;selection-background-color: #600000;selection-color: white;}");
    painter->restore();
    }
    break;

    }

  20. #20
    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

    Another case of using a drawing routine to do something unrelated to drawing.
    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.