<?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[Counter of touches]]></title><description><![CDATA[<p dir="auto">Hello. I try to make a simple example that shows a counter of touches:</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/6446bf54-267a-4a29-8340-312b33985b3d.png" alt="13169593-4a33-48f8-9517-386392b3677c-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">I set this attribute:</p>
<pre><code class="language-cpp">setAttribute(Qt::WA_AcceptTouchEvents);
</code></pre>
<p dir="auto">I built the APK file and ran it on Android but the counter of touches isn't changed:</p>
<p dir="auto">widget.h</p>
<pre><code class="language-cpp">#ifndef WIDGET_H
#define WIDGET_H

#include &lt;QtGui/QTouchEvent&gt;
#include &lt;QtWidgets/QLabel&gt;
#include &lt;QtWidgets/QWidget&gt;

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

protected:
    bool event(QEvent *event) override;

private:
    QLabel *m_counterOfTouchesLabel;
    int m_counterOfTouches = 0;
};
#endif // WIDGET_H
</code></pre>
<p dir="auto">widget.cpp</p>
<pre><code class="language-cpp">#include "widget.h"
#include &lt;QtWidgets/QHBoxLayout&gt;

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    setWindowTitle("Touch Coords");
    resize(300, 300);
    setAttribute(Qt::WA_AcceptTouchEvents);

    QHBoxLayout *hbox = new QHBoxLayout(this);
    m_counterOfTouchesLabel = new QLabel("Counter of touches: 0");
    hbox-&gt;addWidget(m_counterOfTouchesLabel);
    setLayout(hbox);
}

Widget::~Widget()
{
}

bool Widget::event(QEvent *event)
{
    switch (event-&gt;type())
    {
        case QEvent::TouchBegin:
            m_counterOfTouches++;
            m_counterOfTouchesLabel-&gt;setText("Counter of touches:" +
                QString::number(m_counterOfTouches));
            break;
        default:
            break;
    }

    return true;
}
</code></pre>
]]></description><link>https://forum.qt.io/topic/148757/counter-of-touches</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Sep 2026 14:09:38 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/148757.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 30 Aug 2023 20:33:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Counter of touches on Wed, 30 Aug 2023 22:04:03 GMT]]></title><description><![CDATA[<p dir="auto">Solution:</p>
<pre><code class="language-cpp">bool Widget::event(QEvent *event)
{
    if (event-&gt;type() == QEvent::TouchBegin)
    {
        m_counterOfTouches++;
        m_counterOfTouchesLabel-&gt;setText("Counter of touches: " +
            QString::number(m_counterOfTouches));
        return true;
    }

    return QWidget::event(event);
}
</code></pre>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/6090ccf3-f0ea-49bf-add0-2858d7fa9800.gif" alt="touch-coords-qt6-cpp.gif" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/770942</link><guid isPermaLink="true">https://forum.qt.io/post/770942</guid><dc:creator><![CDATA[8Observer8]]></dc:creator><pubDate>Wed, 30 Aug 2023 22:04:03 GMT</pubDate></item></channel></rss>