最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

touchscreen - The touch screen is larger than the LCD screen. How can Qt detect touch screen events outside the LCD area? - Stac

programmeradmin3浏览0评论

In our application, the touch screen is larger than the LCD screen, and touch buttons are set outside the LCD screen, as shown here:

However, Qt can only detect touch events within the LCD screen, and it cannot detect touch events outside of the LCD. We use QTouchEvent to handle the touch.

#include <QApplication>
#include <QWidget>
#include <QDebug>
#include <QTouchEvent>

class TouchWidget : public QWidget {
public:
    TouchWidget(QWidget *parent = nullptr) : QWidget(parent) {
        setWindowTitle("Qt touch detect");
        resize(380, 240);
        setAttribute(Qt::WA_AcceptTouchEvents);
    }

protected:
    bool event(QEvent *event) override {
        if (event->type() == QEvent::TouchBegin ||
            event->type() == QEvent::TouchUpdate ||
            event->type() == QEvent::TouchEnd) {

            QTouchEvent *touchEvent = static_cast<QTouchEvent*>(event);
            for (const QTouchEvent::TouchPoint &point : touchEvent->touchPoints()) {
                qDebug() << "touch point:" << point.pos();
            }
            return true;
        }
        return QWidget::event(event);
    }
};

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);

    QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents);
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    TouchWidget window;
    window.show();

    return app.exec();
}

Is there any way to solve this problem?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论