Skip to content

Commit

Permalink
fix: use custom event filter for QWebEngineView. (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
JuBan1 authored and danieleds committed Jul 24, 2018
1 parent 2528828 commit 63a416e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/ui/EditorNS/customqwebview.cpp
Expand Up @@ -61,4 +61,35 @@ namespace EditorNS

menu->popup(event->globalPos());
}

bool EditorNS::CustomQWebView::eventFilter(QObject* obj, QEvent* ev)
{
if (obj != childObj)
return QWebEngineView::eventFilter(obj, ev);

switch (ev->type()) {
case QEvent::FocusIn:
focusInEvent(static_cast<QFocusEvent*>(ev));
break;
case QEvent::KeyPress:
keyPressEvent(static_cast<QKeyEvent*>(ev));
break;
}

return QWebEngineView::eventFilter(obj, ev);
}

bool EditorNS::CustomQWebView::event(QEvent* evt)
{
if (evt->type() == QEvent::ChildPolished) {
QChildEvent* child_ev = static_cast<QChildEvent*>(evt);
childObj = child_ev->child();

if (childObj) {
childObj->installEventFilter(this);
}
}

return QWebEngineView::event(evt);
}
}
11 changes: 11 additions & 0 deletions src/ui/include/EditorNS/customqwebview.h
Expand Up @@ -24,6 +24,17 @@ namespace EditorNS
void dropEvent(QDropEvent *ev) override;
void focusInEvent(QFocusEvent* event) override;
void contextMenuEvent(QContextMenuEvent* ev) override;

/*
* QWebEngineView eats various types of events. Since we still need them
* we'll have to install a custom event filter on the WebView's child delegate
* QOpenGLWidget.
*/
bool event(QEvent* evt) override;
bool eventFilter(QObject *obj, QEvent *ev) override;

private:
QObject *childObj = nullptr;
};

}
Expand Down

0 comments on commit 63a416e

Please sign in to comment.