<?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[QToolTip::showText doesn&#x27;t work in GraphicsView click handler]]></title><description><![CDATA[<p dir="auto">I want to show a tooltip whenever the user clicks on a <code>QGraphicsView</code> widget.  To expose a click handler, I have created the following subclass of <code>QGraphicsView</code> called <code>ClickableGraphicsView </code>:</p>
<pre><code>class ClickableGraphicsView : public QGraphicsView
{
    Q_OBJECT
public:
    ClickableGraphicsView() : QGraphicsView() {}
    ClickableGraphicsView(QWidget *parent) : QGraphicsView(parent) {}

public:
    void mousePressEvent(QMouseEvent *event) {
        QGraphicsView::mousePressEvent(event);
        emit this-&gt;clicked(event);
    }
    void mouseDoubleClickEvent(QMouseEvent *event) {
        QGraphicsView::mouseDoubleClickEvent(event);
        emit this-&gt;clicked(event);
    }

signals:
    void clicked(QMouseEvent *event);
};
</code></pre>
<p dir="auto">This seems to work great--I can successfully hook into the <code>clicked</code> signal.  However, the tooltip does not appear anywhere.</p>
<pre><code>QObject::connect(myClickableGraphicsView, &amp;ClickableGraphicsView::clicked, [=](){
    // This is called successfully, logic runs fine.
    DoStuff();

    // This doesn't work!
    QToolTip::showText(QPoint(0, 0), "This doesn't work...");
});
</code></pre>
<p dir="auto">When I setup the exact same code, but for a <code>QPushButton</code>, the tooltip <em><strong>does</strong></em> show up in the top-left corner, as expected.</p>
<pre><code>QObject::connect(myPushButton, &amp;QPushButton::clicked, [=](){
    QToolTip::showText(QPoint(0, 0), "This works!");
}
</code></pre>
<p dir="auto">I tried some other techniques, like emitting a signal from these click handlers, but the same issue persists.  I'm a bit out of ideas now.  Is there something inherent about a <code>QGraphicsView</code>'s event-handling system that would get in the way of the tooltip?  Thanks!</p>
]]></description><link>https://forum.qt.io/topic/139220/qtooltip-showtext-doesn-t-work-in-graphicsview-click-handler</link><generator>RSS for Node</generator><lastBuildDate>Sun, 01 Nov 2026 01:14:34 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/139220.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 10 Sep 2022 17:17:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QToolTip::showText doesn&#x27;t work in GraphicsView click handler on Wed, 28 Sep 2022 12:38:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> Thanks--this works perfectly and resolves my issue.</p>
]]></description><link>https://forum.qt.io/post/730539</link><guid isPermaLink="true">https://forum.qt.io/post/730539</guid><dc:creator><![CDATA[huderlem]]></dc:creator><pubDate>Wed, 28 Sep 2022 12:38:52 GMT</pubDate></item><item><title><![CDATA[Reply to QToolTip::showText doesn&#x27;t work in GraphicsView click handler on Tue, 27 Sep 2022 07:11:21 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
Make sure you emit Clicked in Release event not pressEvent as that seems to not work as expected.</p>
<pre><code>
#include &lt;QMouseEvent&gt;
#include &lt;qgraphicsview.h&gt;
#include &lt;qgraphicsscene.h&gt;
#include &lt;QToolTip&gt;
#include &lt;QGraphicsView&gt;

class MyGraphicsView : public QGraphicsView
{
    Q_OBJECT
public:
    MyGraphicsView(QWidget *parent = nullptr) : QGraphicsView(parent) { }
    void mouseReleaseEvent(QMouseEvent *pMouseEvent) override
    {
        QGraphicsView::mouseReleaseEvent(pMouseEvent);
        emit clicked();
    }
signals:
    void clicked();
};

-- usage ---
  QObject::connect(  ui-&gt;graphicsView, &amp;MyGraphicsView::clicked, [this]() {
        QToolTip::showText( ui-&gt;graphicsView-&gt;mapToGlobal(QPoint(0, 0)),
                            "This doesn't work...");
    });

note the mapToGlobal
</code></pre>
<p dir="auto">result<br />
<img src="https://i.postimg.cc/SKhhLnk6/drop4.gif" alt="alt text" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/730295</link><guid isPermaLink="true">https://forum.qt.io/post/730295</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Tue, 27 Sep 2022 07:11:21 GMT</pubDate></item><item><title><![CDATA[Reply to QToolTip::showText doesn&#x27;t work in GraphicsView click handler on Mon, 26 Sep 2022 19:16:14 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Can you provide a minimal compilable example ?<br />
By the way, which Qt version and OS are you using ?</p>
]]></description><link>https://forum.qt.io/post/730260</link><guid isPermaLink="true">https://forum.qt.io/post/730260</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 26 Sep 2022 19:16:14 GMT</pubDate></item><item><title><![CDATA[Reply to QToolTip::showText doesn&#x27;t work in GraphicsView click handler on Sun, 25 Sep 2022 19:41:52 GMT]]></title><description><![CDATA[<p dir="auto">Bumping this, since I haven't received a response, yet.</p>
]]></description><link>https://forum.qt.io/post/730127</link><guid isPermaLink="true">https://forum.qt.io/post/730127</guid><dc:creator><![CDATA[huderlem]]></dc:creator><pubDate>Sun, 25 Sep 2022 19:41:52 GMT</pubDate></item></channel></rss>