<?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[How to avoid losing mouse events?]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">i am developing a image editor/painting application and i have the following problem:</p>
<p dir="auto">I receive the mouse events, i draw on a QImage, convert it to QPixmap, show it on the screen.</p>
<p dir="auto">The drawing operation for debuging purposes at the moment is to draw a simple rectangle on the mouse position via QPainter on the QImage</p>
<p dir="auto">Now the problem is: as long as i do this on a 512x512 image, everything seems fine, but if i do it on a 4096x4096 image, most mouse events are lost an i only get one every half a second or so.</p>
<p dir="auto">I tried different approaches so far:</p>
<p dir="auto">a) do the drawing operations in the mouse event handler</p>
<p dir="auto">b) in mouse event handler, start a thread that does the drawing operations, this one failed because you can not draw on a QPixmap in a thread... which is why i tried approach c:</p>
<p dir="auto">c) in mouse event handler, start a thread that does the drawing on the QImage and then emits a signal that is connected to the main window, which updates the QPixmap on screen</p>
<p dir="auto">All three have the same problem: Mouse events get lost.</p>
<p dir="auto">How can i prevent this, or what are my options to change the general workflow for better performance?</p>
<p dir="auto">Thanx</p>
]]></description><link>https://forum.qt.io/topic/29989/how-to-avoid-losing-mouse-events</link><generator>RSS for Node</generator><lastBuildDate>Thu, 12 Nov 2026 04:03:37 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/29989.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 28 Jul 2013 05:20:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to avoid losing mouse events? on Sun, 28 Jul 2013 16:18:54 GMT]]></title><description><![CDATA[<p dir="auto">Maybe you want to use <em>c)</em>, but also <em>coalesce</em> the events in order to limit the number QPixmap updates in the "main" thread. That is: If several events are encountered within a short time, update the QImage in the "background" thread for each event, but only trigger an update of the QPixmap <em>once</em>.</p>
<p dir="auto">A simple solution would be to simply <em>delay</em> the <em>signal</em> that is sent from the "background" thread to the "main" thread. That is: If the background thread processes an event, it starts a timer. If the timer is triggered, the signal will be sent. But if a new event is encountered <em>before</em> the timer was triggered, stop the timer, process the new event and re-start the timer. There also should be a limit of the maximum overall delay, of course...</p>
]]></description><link>https://forum.qt.io/post/188212</link><guid isPermaLink="true">https://forum.qt.io/post/188212</guid><dc:creator><![CDATA[MuldeR]]></dc:creator><pubDate>Sun, 28 Jul 2013 16:18:54 GMT</pubDate></item><item><title><![CDATA[Reply to How to avoid losing mouse events? on Sun, 28 Jul 2013 11:30:05 GMT]]></title><description><![CDATA[<p dir="auto">It's a pure performance problem, not mouse events one.<br />
First of all I wouldn't create separate thread every time as it's time consuming on it's own. Keep an event loop in a separate working thread and communicate thrrough signals and slots or use a  qthreadpool, whichever turns to be faster.<br />
Another thing is that 4096x4096 is a pretty big image, and chances are - you're not redrawing all of it every time so if it's possible try to update just the small fragment that actually changes and apply this to the resulting image.<br />
Another option is to go for hardware acceleration - since you're working with pretty big images you might want to look into opengl. Displaying a single quad is a breeze for a gpu and you would be updating the texture for it in a separate thread. Kinda like what you have in c) but a lot faster.</p>
]]></description><link>https://forum.qt.io/post/188194</link><guid isPermaLink="true">https://forum.qt.io/post/188194</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Sun, 28 Jul 2013 11:30:05 GMT</pubDate></item></channel></rss>