为什么触摸屏不适用于WebAssembly?

发布于 2025-01-27 11:19:06 字数 5050 浏览 1 评论 0原文

我正在开发一个必须使用触摸屏的WebAssembly应用程序。 我研究了示例: 表盘 指纹 旋钮 Pinchzoom (请参阅 /a>)

我尝试运行平板电脑示例(请参阅 https ://doc.qt.io/qt-6/qtwidgets-widgets-tablet-example.html )在WebAssembly中编译但不起作用。 我有一个问题: 如果我使用mingw套件(桌面应用程序)编译我的应用程序,则可以用手指在标题部分上移动一个对话框,并且 我可以看到显示以下事件的调试打印:

QEvent::WindowActivate
QEvent::NonClientAreaMouseMove
QEvent::NonClientAreaMouseButtonPress
QEvent::NonClientAreaMouseButtonRelease
QEvent::NonClientAreaMouseMove

如果我使用WebAssembly套件(WebAssembly应用程序)编译了我的应用程序,我将无法移动标题上的对话框。 这些是我可以看到在控制台上打印的事件的事件:

QEvent::MouseMove
QEvent::MouseButtonRelease
QEvent::MouseButtonPress

我尝试用wa_accepttouchevents设置为false,befor并将设置为true来重复测试。但是我有同样的行为。

我的问题是:如何在两种配置中执行相同的行为 我发布了针对同一问题影响的最小申请 该示例由MainWindow组成,该MainWindow在菜单文件上显示了一个非模态对话框,打开。 对话框是一个简单的默认QDialog,带有两个按钮(确定并取消) 我的配置:

QT Creator 7.0.0基于QT 6.2.3(MSVC 2019,64位) 638B93591B

QT 6.3.0 WebAssembly,emscripten 3.1.6用于C ++

Google Chrome Ver。 101.0.4951.54

// here the WasmDialog.pro file 

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++17

SOURCES += \
    ExtGraphicsWidget.cpp \
    WasmDialog.cpp \
    main.cpp \
    MainWindow.cpp

HEADERS += \
    ExtGraphicsWidget.h \
    MainWindow.h \
    WasmDialog.h

FORMS += \
    mainwindow.ui \
    wasmdialog.ui

qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target


// here main.cpp code:

#include "MainWindow.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}

// here the MainWindow.h file 

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "WasmDialog.h"

QT_BEGIN_NAMESPACE
namespace Ui { 
    class MainWindow; 
}

QT_END_NAMESPACE

class QGraphicsView;
class QGraphicsScene;
class ExtGraphicsWidget;

class MainWindow : public QMainWindow
{
    Q_OBJECT

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

    private:
        Ui::MainWindow *ui;
        WasmDialog moWD;
        QGraphicsView *mpView;
        QGraphicsScene *mpScene;
};
#endif // MAINWINDOW_H

// here the MainWindow.cpp file 

#include "MainWindow.h"
#include "ui_mainwindow.h"

#include <ExtGraphicsWidget.h>

#include <QGraphicsView>
#include <QGraphicsAnchorLayout>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    , mpView(nullptr)
    , mpScene(nullptr)
{
    ui->setupUi(this);
    setAttribute(Qt::WA_AcceptTouchEvents, false);

    connect(ui->actionOpen, &QAction::triggered, &moWD, &WasmDialog::show);

    mpScene = new QGraphicsScene(this);
    mpView = new QGraphicsView(this);
    mpView->setScene(mpScene);
    setCentralWidget(mpView);
} // ctr

MainWindow::~MainWindow()
{
    if (nullptr != mpScene)
    {
        delete mpScene;
    } // end if nullptr != mpScene)

    if (nullptr != mpView)
    {
        delete mpView;
    } // end if nullptr != mpView)

    delete ui;
} // dtr

// here the WasmDialog.h file 

#ifndef WASMDIALOG_H
#define WASMDIALOG_H

#include <QDialog>

namespace Ui 
{
    class WasmDialog;
}

class WasmDialog : public QDialog
{
    Q_OBJECT

    public:
        explicit WasmDialog(QWidget *parent = nullptr);
        ~WasmDialog();

    protected:
        bool event(QEvent *event) override;
        void tabletEvent(QTabletEvent *event) override;

    private:
        Ui::WasmDialog *ui;
};

#endif // WASMDIALOG_H

// here the WasmDialog.cpp file 

#include "WasmDialog.h"
#include "ui_wasmdialog.h"

#include <QDebug>
#include <QMoveEvent>

WasmDialog::WasmDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::WasmDialog)
{
    ui->setupUi(this);
    setAttribute(Qt::WA_AcceptTouchEvents, false);
    setWindowFlags(windowFlags() | Qt::WindowTitleHint);

} // ctr

WasmDialog::~WasmDialog()
{
    delete ui;
} // dtr

bool WasmDialog::event(QEvent *event)
{
    qDebug() << " e->type " <<  event->type();
    return QDialog::event(event);
}

void WasmDialog::tabletEvent(QTabletEvent *event)
{
    switch (event->type())
    {
        case QEvent::TabletPress:
        case QEvent::TabletMove:
        {
            qDebug() << " e->type " <<  event->type();
            break;
        }
        case QEvent::TabletRelease:
        {
            qDebug() << " e->type " <<  event->type();
            update();
            break;
        }
        default:
        {
            break;
        }
    }
    QDialog::tabletEvent(event);
}

I'm developing an webassembly application that must use touchscreen.
I studied the examples:
dials
fingerpaint
knobs
pinchzoom
(see https://doc.qt.io/qt-6/touchinputexamples.html)

I tryed to run the tablet example (see https://doc.qt.io/qt-6/qtwidgets-widgets-tablet-example.html) compiled in webassembly but don't work.
I have this problem:
If I compile my application with MinGW kit (Desktop application), I'm able to move a dialog tapped on title section with my finger, and
I can see the debug print that show the events below:

QEvent::WindowActivate
QEvent::NonClientAreaMouseMove
QEvent::NonClientAreaMouseButtonPress
QEvent::NonClientAreaMouseButtonRelease
QEvent::NonClientAreaMouseMove

If I compile my application with WebAssembly kit (WebAssembly application), I'm NOT able to move the dialog tapped on title.
these are the event that I can see the event printed on console:

QEvent::MouseMove
QEvent::MouseButtonRelease
QEvent::MouseButtonPress

I tryed to repete the test with the WA_AcceptTouchEvents sets to false, befor and sets to true after. But I had the same behavior.

My question is: how can I perform the same behaviour in both configurations
I posted a minimal application affected for same issue
The example is composed by a MainWindow that show a non modal dialog, across the menu file, open.
The dialog is a simple default QDialog with two button (ok and cancel)
My configuration:

Qt Creator 7.0.0 Based on Qt 6.2.3 (MSVC 2019, 64 bit) From revision
638b93591b

Qt 6.3.0 WebAssembly with Emscripten 3.1.6 for C++

Google Chrome Ver. 101.0.4951.54

// here the WasmDialog.pro file 

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++17

SOURCES += \
    ExtGraphicsWidget.cpp \
    WasmDialog.cpp \
    main.cpp \
    MainWindow.cpp

HEADERS += \
    ExtGraphicsWidget.h \
    MainWindow.h \
    WasmDialog.h

FORMS += \
    mainwindow.ui \
    wasmdialog.ui

qnx: target.path = /tmp/${TARGET}/bin
else: unix:!android: target.path = /opt/${TARGET}/bin
!isEmpty(target.path): INSTALLS += target


// here main.cpp code:

#include "MainWindow.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}

// here the MainWindow.h file 

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "WasmDialog.h"

QT_BEGIN_NAMESPACE
namespace Ui { 
    class MainWindow; 
}

QT_END_NAMESPACE

class QGraphicsView;
class QGraphicsScene;
class ExtGraphicsWidget;

class MainWindow : public QMainWindow
{
    Q_OBJECT

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

    private:
        Ui::MainWindow *ui;
        WasmDialog moWD;
        QGraphicsView *mpView;
        QGraphicsScene *mpScene;
};
#endif // MAINWINDOW_H

// here the MainWindow.cpp file 

#include "MainWindow.h"
#include "ui_mainwindow.h"

#include <ExtGraphicsWidget.h>

#include <QGraphicsView>
#include <QGraphicsAnchorLayout>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    , mpView(nullptr)
    , mpScene(nullptr)
{
    ui->setupUi(this);
    setAttribute(Qt::WA_AcceptTouchEvents, false);

    connect(ui->actionOpen, &QAction::triggered, &moWD, &WasmDialog::show);

    mpScene = new QGraphicsScene(this);
    mpView = new QGraphicsView(this);
    mpView->setScene(mpScene);
    setCentralWidget(mpView);
} // ctr

MainWindow::~MainWindow()
{
    if (nullptr != mpScene)
    {
        delete mpScene;
    } // end if nullptr != mpScene)

    if (nullptr != mpView)
    {
        delete mpView;
    } // end if nullptr != mpView)

    delete ui;
} // dtr

// here the WasmDialog.h file 

#ifndef WASMDIALOG_H
#define WASMDIALOG_H

#include <QDialog>

namespace Ui 
{
    class WasmDialog;
}

class WasmDialog : public QDialog
{
    Q_OBJECT

    public:
        explicit WasmDialog(QWidget *parent = nullptr);
        ~WasmDialog();

    protected:
        bool event(QEvent *event) override;
        void tabletEvent(QTabletEvent *event) override;

    private:
        Ui::WasmDialog *ui;
};

#endif // WASMDIALOG_H

// here the WasmDialog.cpp file 

#include "WasmDialog.h"
#include "ui_wasmdialog.h"

#include <QDebug>
#include <QMoveEvent>

WasmDialog::WasmDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::WasmDialog)
{
    ui->setupUi(this);
    setAttribute(Qt::WA_AcceptTouchEvents, false);
    setWindowFlags(windowFlags() | Qt::WindowTitleHint);

} // ctr

WasmDialog::~WasmDialog()
{
    delete ui;
} // dtr

bool WasmDialog::event(QEvent *event)
{
    qDebug() << " e->type " <<  event->type();
    return QDialog::event(event);
}

void WasmDialog::tabletEvent(QTabletEvent *event)
{
    switch (event->type())
    {
        case QEvent::TabletPress:
        case QEvent::TabletMove:
        {
            qDebug() << " e->type " <<  event->type();
            break;
        }
        case QEvent::TabletRelease:
        {
            qDebug() << " e->type " <<  event->type();
            update();
            break;
        }
        default:
        {
            break;
        }
    }
    QDialog::tabletEvent(event);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜唯美灬不弃 2025-02-03 11:19:06

这是在WebAssemblu 6.3.0上发现的错误:
https://bugreports.qt.io/browse/browse/qtbug-103498

this is a bug discovered on WebAssemblu 6.3.0:
https://bugreports.qt.io/browse/QTBUG-103498

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文