0

I'm running a Qt 5.9.4 app with QWebView on a touch linux device displaying HTML webpages.

When users pinch their fingers on the screen, they zoom into the webpage. I want to disable that behaviour, because all the webpages should be 100% fullscreen.

I could temporarily disable it in the webpages (since I own their code) by adding user-scalable=no to the viewport, but that wont work in the long run because not every webpage will have that.

I tried to use eventFilter on different elements of my app, but couldn't get any Gesture or even Mouse event to catch.

This is how I create my webview (in a QDialog):

void Dialog::createWebView() {
  view = new QWebEngineView(this);
  profile = new QWebEngineProfile();
  page = new QWeEnginePage(profile);
  view->setPage(page);
  view->setUrl(QUrl(path));
}

This is my eventFilter class:

EvFilter::EvFilter(QObject *parent) : QObject(parent)
{

}

bool EvFilter::eventFilter(QObject *obj, QEvent *event)
{

    qDebug() << event->type() << "\n";
    return QObject::eventFilter(obj, event);
}

I have tried doing

EvFilter* evf = new EvFilter();
view->installEventFilter(evf);

And also on every other element (profile, page, dialog) but couldn't seem to get any events corresponding to mouse or gesture. What am I doing wrong? How could I prevent that behaviour in the entire webview?

After adding the event listener to the QApplication object, I can detect TouchBegin, TouchUpdate, TouchCancel and TouchEnd events, but nothing else (no Gesture event). I dont know how could I detect if the touchevent is the zoom gesture.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
AJ Cole
  • 169
  • 2
  • 13
  • try add `EvFilter* evf = new EvFilter(); view->focusProxy()->installEventFilter(evf);` after `view->setUrl(QUrl(path));` – eyllanesc Sep 26 '19 at 15:56
  • @eyllanesc unfortunately it works the same way as installing it on whole QApplication, I can see Touch events, but i have no idea how to know when they are used for zooming and when they are just normal touch events. I'd like to completely disable zooming, on all devices. Is it possible? I can't find any settings to disable zoom. – AJ Cole Oct 02 '19 at 07:12

1 Answers1

1

I think you could use this on the Dialog (didn't test it). I had some other widget showing a QML QtWebView and what I did to prevent the widget's children to get Pinch Gestures is:

this->grabGesture(Qt::PinchGesture, Qt::DontStartGestureOnChildren);

This prevents the underlying widget from receiving the PinchGesture, so that you can handle it yourself.

Hans
  • 81
  • 1
  • 3