<?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 receive gesture events on a QGraphicsItem ?]]></title><description><![CDATA[<p dir="auto">I already set:</p>
<p dir="auto">@<br />
graphicsView-&gt;setAttribute(Qt::WA_AcceptTouchEvents);<br />
graphicsView-&gt;viewport()-&gt;setAttribute(Qt::WA_AcceptTouchEvents);<br />
graphicsView-&gt;grabGesture(Qt::PinchGesture);<br />
graphicsView-&gt;viewport()-&gt;grabGesture(Qt::PinchGesture);<br />
@</p>
<p dir="auto">And I'm still unable to receive gestures on the <em>sceneEvent</em> of a <em>QGraphicsItem</em> using Qt 5.1, does anyone knows why ?</p>
]]></description><link>https://forum.qt.io/topic/32026/how-to-receive-gesture-events-on-a-qgraphicsitem</link><generator>RSS for Node</generator><lastBuildDate>Sat, 07 Nov 2026 13:03:18 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/32026.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 16 Sep 2013 16:45:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to receive gesture events on a QGraphicsItem ? on Tue, 17 Sep 2013 13:20:17 GMT]]></title><description><![CDATA[<p dir="auto">Great thanks Raven, the wrapper worked fine, it was missing only the implementation of the paint() method.</p>
]]></description><link>https://forum.qt.io/post/195611</link><guid isPermaLink="true">https://forum.qt.io/post/195611</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 17 Sep 2013 13:20:17 GMT</pubDate></item><item><title><![CDATA[Reply to How to receive gesture events on a QGraphicsItem ? on Tue, 17 Sep 2013 13:05:01 GMT]]></title><description><![CDATA[<p dir="auto">hope this works for you (haven't tried it):</p>
<p dir="auto">@<br />
class MyGraphicsObjectWrapper : public QGraphicsObject<br />
{<br />
Q_OBJECT</p>
<p dir="auto">public:<br />
MyGraphicsObjectWrapper( QGraphicsItem* item )<br />
: m_Item(item)<br />
{<br />
this-&gt;grabGesture( ... );<br />
m_Item-&gt;setParentItem(this);<br />
}</p>
<pre><code>virtual QRectF boundingRect () const {  return m_Item-&gt;boundingRect(); }

virtual QPainterPath opaqueArea () const {  return m_Item-&gt;opaqueArea(); }

virtual QPainterPath shape () const  {  return m_Item-&gt;shape(); }
</code></pre>
<p dir="auto">protected:<br />
virtual bool sceneEvent ( QEvent * event )<br />
{<br />
if( event-&gt;type() == QEvent::Gesture )<br />
{<br />
....<br />
}<br />
return QGraphicsObject::sceneEvent(event);<br />
}</p>
<pre><code>QGraphicsItem*   m_Item;
</code></pre>
<p dir="auto">};<br />
@</p>
<p dir="auto">usage:<br />
@<br />
QGraphicsRectItem* rectItem( QRectF() );<br />
scene-&gt;addItem( new MyGraphicsObjectWrapper( rectItem ) );<br />
@</p>
<p dir="auto">If that's too much implementation for you you may also go simply with virtual inheritance:<br />
@<br />
class MyGraphicsRectItem : public virtual QGraphicsObject, public virtual QGraphicsRectItem<br />
{<br />
Q_OBJECT</p>
<p dir="auto">public:<br />
MyGraphicsRectItem( ... );<br />
};<br />
@</p>
]]></description><link>https://forum.qt.io/post/195610</link><guid isPermaLink="true">https://forum.qt.io/post/195610</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Tue, 17 Sep 2013 13:05:01 GMT</pubDate></item><item><title><![CDATA[Reply to How to receive gesture events on a QGraphicsItem ? on Tue, 17 Sep 2013 12:09:44 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for the quick answer raven, I'm not doing the painting myself I'm just using the QGraphicsRectItem as a base class for a class implementing the sceneEvent() method to receive the gestures. What you mean by wrap the items with a QGraphicsObject ? Thanks !</p>
]]></description><link>https://forum.qt.io/post/195600</link><guid isPermaLink="true">https://forum.qt.io/post/195600</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 17 Sep 2013 12:09:44 GMT</pubDate></item><item><title><![CDATA[Reply to How to receive gesture events on a QGraphicsItem ? on Tue, 17 Sep 2013 12:06:12 GMT]]></title><description><![CDATA[<p dir="auto">right my fault, the grabGesture() is on QGraphicsObject.</p>
<p dir="auto">Do you use custom QGraphicsItems? Meaning doing the painting yourself?<br />
If so you can just derive from QGraphicsObject insteaf of QGraphicsItem.</p>
<p dir="auto">Otherwise you would need to wrap your current items with a QGraphicsObject.</p>
]]></description><link>https://forum.qt.io/post/195599</link><guid isPermaLink="true">https://forum.qt.io/post/195599</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Tue, 17 Sep 2013 12:06:12 GMT</pubDate></item><item><title><![CDATA[Reply to How to receive gesture events on a QGraphicsItem ? on Tue, 17 Sep 2013 12:01:39 GMT]]></title><description><![CDATA[<p dir="auto">The QGraphicsItem doesn't have the grabGesture() method, that's the problem.</p>
]]></description><link>https://forum.qt.io/post/195596</link><guid isPermaLink="true">https://forum.qt.io/post/195596</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 17 Sep 2013 12:01:39 GMT</pubDate></item><item><title><![CDATA[Reply to How to receive gesture events on a QGraphicsItem ? on Tue, 17 Sep 2013 06:30:48 GMT]]></title><description><![CDATA[<p dir="auto">you also need to call grabGesture() on the item itself, not only on the qgraphicsview widget.</p>
]]></description><link>https://forum.qt.io/post/195536</link><guid isPermaLink="true">https://forum.qt.io/post/195536</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Tue, 17 Sep 2013 06:30:48 GMT</pubDate></item></channel></rss>