Mariusz Jaskółka
Mariusz Jaskółka

Reputation: 4492

QTouchEvent instead QMouseEvent on Linux

I am trying to handle QTouchEvent from M3 touchscreen in Qt 5.9. I use Qt Finger Print example and it works fine on Windows 7 but on Ubuntu 16.04 I receive mouse events instead of touch events. Is it Qt's fault or wrong OS configuration?

What is more QTouchDevice::devices().size() always equals 0.

Upvotes: 21

Views: 951

Answers (1)

Marcelino
Marcelino

Reputation: 331

I suggest you to use EventFilters to catch touch and mouse events in multiple platforms. To doing this you have to call installEventFilter in the constructor of your widget and implement the eventFilter to filter the QEvent you are looking for. For example using something like this:

bool ECGPlot::eventFilter(QObject *o, QEvent *ev) {
    bool ret = false;

    switch (ev->type ()) {
        case QEvent::TouchBegin:
            ret = true;
            break;

        case QEvent::TouchUpdate:
            ret = true;
            break;

        case QEvent::TouchEnd:
            ret = true;
            break;

        case QEvent::Wheel:
            ret = true;
            break;

        case QEvent::MouseButtonPress:
            ret = true;
            break;

        case QEvent::MouseButtonRelease:
            ret = true;
            break;

        case QEvent::MouseMove:
            ret = true;
            break;

    }

    return ret;
}

Upvotes: 1

Related Questions