<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Rendering animations on Qt&#x2F;E using timers]]></title><description><![CDATA[<p dir="auto">Hi! I need to create an animation for which I thought it might be simpler using timer instead of the animation framework. I'm using a QGraphicsView with a OpenGL viewport and full screen viewport update. So, I subclassed QObject and I ran startTimer(). In my timerEvent(...) method I simply compute the new positions of some items and I call the setPos() on each of those objects.</p>
<p dir="auto">What I'm noticing is that the timerEvent code is taking only a couple of ms (does a setPos triggers a redraw of the entire screen?), the average frame rate is constant but the interval between two calls of my timerEvent method is not. I noticed it is always within a couple of ms from the chosen value, but in some cases it is 3 or 4 times higher. This creates really an horrible effect, so it is a problem.</p>
<p dir="auto">Does anybody know why this is happening and if there is any way to avoid it?<br />
Thanks!</p>
]]></description><link>https://forum.qt.io/topic/10916/rendering-animations-on-qt-e-using-timers</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 17:22:21 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/10916.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 01 Nov 2011 03:23:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Rendering animations on Qt&#x2F;E using timers on Sat, 05 Nov 2011 11:01:39 GMT]]></title><description><![CDATA[<p dir="auto">Thanks! I'll read those. Anyway, I suppose my problem is due to the fact that simply rendering is taking too much time. Thanks!</p>
]]></description><link>https://forum.qt.io/post/115691</link><guid isPermaLink="true">https://forum.qt.io/post/115691</guid><dc:creator><![CDATA[Luc4]]></dc:creator><pubDate>Sat, 05 Nov 2011 11:01:39 GMT</pubDate></item><item><title><![CDATA[Reply to Rendering animations on Qt&#x2F;E using timers on Thu, 03 Nov 2011 05:37:51 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="Luc4" date="1320273190"]Only things I can think is it is taking too long to paint, and therefore when the timer should be triggered it is busy drawing. May this be realistic?<br />
[/quote]<br />
Yes, it's realy so. I've tested it, and have the same situation as you describe.<br />
Timer has this periodic (I've set 25 ms):<br />
25<br />
56<br />
80<br />
105<br />
129<br />
153<br />
177 .... and so on.<br />
So, try to cache some vars, if you calculate them in paintEvent(), calculate them beforre paint and recalculate when you have some changes. Also you can cache whole painting, if you have some static picture, paint it in some image and then draw only image.<br />
And you can try to look this presentation from DevDays 2010 about Graphics Framework.<br />
Here they are: "1":<a href="http://developer.qt.nokia.com/videos/watch/performance_do_graphics_the_right_way" target="_blank" rel="noopener noreferrer nofollow ugc">http://developer.qt.nokia.com/videos/watch/performance_do_graphics_the_right_way</a> "2":<a href="http://developer.qt.nokia.com/videos/watch/qt_graphicsview_in_depth" target="_blank" rel="noopener noreferrer nofollow ugc">http://developer.qt.nokia.com/videos/watch/qt_graphicsview_in_depth</a></p>
]]></description><link>https://forum.qt.io/post/115424</link><guid isPermaLink="true">https://forum.qt.io/post/115424</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Thu, 03 Nov 2011 05:37:51 GMT</pubDate></item><item><title><![CDATA[Reply to Rendering animations on Qt&#x2F;E using timers on Wed, 02 Nov 2011 22:33:10 GMT]]></title><description><![CDATA[<p dir="auto">Ok, thanks. I'm testing this and seems to be ok. Problem is it is exactly what I do. Only things I can think is it is taking too long to paint, and therefore when the timer should be triggered it is busy drawing. May this be realistic?<br />
Any way I can find out what it is busy doing when timer is triggered?<br />
Thanks for your help!</p>
]]></description><link>https://forum.qt.io/post/115411</link><guid isPermaLink="true">https://forum.qt.io/post/115411</guid><dc:creator><![CDATA[Luc4]]></dc:creator><pubDate>Wed, 02 Nov 2011 22:33:10 GMT</pubDate></item><item><title><![CDATA[Reply to Rendering animations on Qt&#x2F;E using timers on Wed, 02 Nov 2011 15:13:20 GMT]]></title><description><![CDATA[<p dir="auto">And you want to see hole test project, "here it is":<a href="https://github.com/rokemoon/TestTimerEvent" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/rokemoon/TestTimerEvent</a></p>
]]></description><link>https://forum.qt.io/post/115385</link><guid isPermaLink="true">https://forum.qt.io/post/115385</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 02 Nov 2011 15:13:20 GMT</pubDate></item><item><title><![CDATA[Reply to Rendering animations on Qt&#x2F;E using timers on Wed, 02 Nov 2011 09:43:01 GMT]]></title><description><![CDATA[<p dir="auto">Sorry, but I haven't any thoughts about the delays, because I've made simple example and all works good.<br />
Maybe it helps you, "here is":<a href="http://paste.kde.org/141092/" target="_blank" rel="noopener noreferrer nofollow ugc">http://paste.kde.org/141092/</a> the cpp of my GraphicsView.</p>
]]></description><link>https://forum.qt.io/post/115344</link><guid isPermaLink="true">https://forum.qt.io/post/115344</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 02 Nov 2011 09:43:01 GMT</pubDate></item><item><title><![CDATA[Reply to Rendering animations on Qt&#x2F;E using timers on Tue, 01 Nov 2011 14:17:47 GMT]]></title><description><![CDATA[<p dir="auto">I've been explained that setPos should anyway trigger a paintEvent but not immediately, but in the following paintEvent. So maybe that doesn't happen immediately.</p>
<p dir="auto">As for the timer this is where I set it up:</p>
<p dir="auto">@void CircularList::startSliding(Direction direction)<br />
{<br />
// Immediately mark as animation flowing. Do nothing if an animation is<br />
// currently flowing.<br />
if (isCurrentlyAnimated)<br />
return;<br />
isCurrentlyAnimated = true;</p>
<p dir="auto">// ...</p>
<p dir="auto">// Start the timer to proceed with the animation.<br />
currentDirection = direction;<br />
timestampStarted = QDateTime::currentMSecsSinceEpoch();<br />
currentTimerId = startTimer(REFRESH_PERIOD);</p>
<p dir="auto">for (int i = 0; i &lt; fullList.size(); i++) {<br />
startPositions.append(fullList[i]-&gt;pos());<br />
}<br />
}@</p>
<p dir="auto">The only interesting thing is startTimer I suppose. I tried many refresh rate values to see the difference. This function is invoked when there is a pressEvent.<br />
When the release is called, I simply stop the timer.</p>
<p dir="auto">@void CircularList::stopSliding()<br />
{<br />
killTimer(currentTimerId);<br />
isCurrentlyAnimated = false;<br />
startPositions.clear();<br />
}@</p>
<p dir="auto">Any idea why I have those delays? My code is almost all here. Is there any way to check if the delay is caused by the CPU being busy doing something?<br />
Thanks!</p>
]]></description><link>https://forum.qt.io/post/115254</link><guid isPermaLink="true">https://forum.qt.io/post/115254</guid><dc:creator><![CDATA[Luc4]]></dc:creator><pubDate>Tue, 01 Nov 2011 14:17:47 GMT</pubDate></item><item><title><![CDATA[Reply to Rendering animations on Qt&#x2F;E using timers on Tue, 01 Nov 2011 10:43:30 GMT]]></title><description><![CDATA[<p dir="auto"><em>Can I setPos without triggering an update?</em><br />
As I now, no (but I could be wrong).<br />
<em>Is it normal that there are such irregular calls of the timerEvent method?</em><br />
Can you post the code where you set and delete timer?</p>
]]></description><link>https://forum.qt.io/post/115217</link><guid isPermaLink="true">https://forum.qt.io/post/115217</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 01 Nov 2011 10:43:30 GMT</pubDate></item><item><title><![CDATA[Reply to Rendering animations on Qt&#x2F;E using timers on Tue, 01 Nov 2011 09:55:05 GMT]]></title><description><![CDATA[<p dir="auto">Ok, I was suspecting that. In this case that is not what I had in mind. I just wanted to set the new positions so that at specified intervals the interface was updated. But what should I use to set the position to avoid updates?</p>
<p dir="auto">Yes, this is my timerEvent method implementation:</p>
<p dir="auto">@void CircularList::timerEvent(QTimerEvent* event)<br />
{<br />
Q_UNUSED(event);</p>
<p dir="auto">// I have to compute position according to time.<br />
QPointF pos;<br />
qint64 currentTimestamp = QDateTime::currentMSecsSinceEpoch();<br />
for (int i = 0; i &lt; fullList.size(); i++) {<br />
computeNewPosition(fullList[i], currentTimestamp, startPositions[i], pos);<br />
fullList[i]-&gt;setPos(pos);<br />
}<br />
}@</p>
<p dir="auto">fullList is a QList of items, which are subclasses of QObject and QGraphicsPixmapItem. Those are the objects I want to move.<br />
computeNewPosition is passed the item to move, the timestamp of the update event, the initial position and sets pos as the new position. I tried to do this some other ways but the same behavior is shown.</p>
<p dir="auto">@inline<br />
void CircularList::computeNewPosition(ListItem* item,<br />
qint64&amp; currentTimestamp,<br />
QPointF&amp; startPos,<br />
QPointF&amp; pos)<br />
{<br />
int direction = (currentDirection == DIRECTION_LEFT) ? -1 : 1;<br />
qint64 elapsedMs = currentTimestamp - timestampStarted;<br />
qreal shift = direction<em>CRUISING_SPEED</em>elapsedMs/1000.0;<br />
qreal xpos = startPos.x() + shift;<br />
pos.setY(item-&gt;pos().y());<br />
pos.setX(xpos);<br />
}@</p>
<p dir="auto">I start the timer when the user presses a button, then I ignore whatever repetition arrives and I kill the timer when the user releases.<br />
I know this is not the most obvious way to do this, but it was only the last attempt.</p>
<p dir="auto">Is it normal that there are such irregular calls of the timerEvent method? Can I setPos without triggering an update?<br />
Thanks!</p>
]]></description><link>https://forum.qt.io/post/115212</link><guid isPermaLink="true">https://forum.qt.io/post/115212</guid><dc:creator><![CDATA[Luc4]]></dc:creator><pubDate>Tue, 01 Nov 2011 09:55:05 GMT</pubDate></item><item><title><![CDATA[Reply to Rendering animations on Qt&#x2F;E using timers on Tue, 01 Nov 2011 05:23:54 GMT]]></title><description><![CDATA[<p dir="auto"><em>does a setPos triggers a redraw of the entire screen?</em><br />
Yes, you've set "QGraphicsView::FullViewportUpdate":<a href="http://doc.qt.nokia.com/latest/qgraphicsview.html#ViewportUpdateMode-enum" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.nokia.com/latest/qgraphicsview.html#ViewportUpdateMode-enum</a> , so item-&gt;setPos() will update all viewport.<br />
Can you give us some snippets if code?</p>
]]></description><link>https://forum.qt.io/post/115179</link><guid isPermaLink="true">https://forum.qt.io/post/115179</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 01 Nov 2011 05:23:54 GMT</pubDate></item></channel></rss>