Qt :: AA_SynthesizeMouseForUnhandledTouchEvents on Windows

I created a simple widget that displays the mouse and passes the events it receives to qDebug()(excerpt):

// ...

MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent), acceptEvents(false)
{
    this->setAttribute(Qt::WA_AcceptTouchEvents);
}

static QEvent::Type const mouseEventTypes[] = {
    QEvent::MouseButtonDblClick,
    QEvent::MouseButtonRelease,
    QEvent::MouseButtonPress,
    QEvent::MouseMove
};

static QEvent::Type const touchEventTypes[] = {
    QEvent::TouchBegin,
    QEvent::TouchUpdate,
    QEvent::TouchEnd
};

template<typename Container, typename Value>
bool contains(Container const & c, Value const & v)
{
    return std::find(std::begin(c), std::end(c), v) != std::end(c);
}

bool MyWidget::event(QEvent * e)
{
    auto type = e->type();
    if(contains(mouseEventTypes, type))
        qDebug() << "MouseEvent";
    else if(contains(touchEventTypes, type))
        qDebug() << "TouchEvent";
    else
        return QWidget::event(e);

    e->setAccepted(this->acceptEvents);
    return true;
}

// ...

const bool acceptEvents = true;
const bool synthesizeMouse = false;

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    app.setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, synthesizeMouse);

    MainWindow gui; // contains a MyWidget as centralWidget
    gui.setAcceptEvents(acceptEvents);
    gui.show();

    return app.exec();
}

However, no matter how I installed acceptEventsand synthesizeMouse, I always get both mouse and touch events when I use the multitouch monitor on my system (which is a Windows 7 system). Is there a way to get touch events on Windows using Qt when touch events are received?

Update:

nomousefromtouch , Qt 5.3, QMouseEvent::source() Qt::MouseEventSynthesizedBySystem (, ... Qt::MouseEventNotSynthesized ), . , , , ( ), / .

+4
1

, . , app.setAttribute() QCoreApplication::setAttribute() , .

.

0

Source: https://habr.com/ru/post/1542909/


All Articles