I extended QWebEngineView
.
#ifndef MYQWEBENGINEVIEW_H
#define MYQWEBENGINEVIEW_H
#include
My demand is disabling the mouse click. Follow Orest's answer, the "w" always is NULL in the Qt 5.9.3.
QOpenGLWidget *w = qobject_cast(child_ev->child());
So I modify the answer follow Orest. That is more suitable for Qt 5.9.x.
#ifndef CUSTOMWEBVIEW_H
#define CUSTOMWEBVIEW_H
#include
#include
#include
#include
class CustomWebView : public QWebEngineView
{
Q_OBJECT
public:
CustomWebView(QWidget* parent = Q_NULLPTR);
protected:
bool event(QEvent* evt)
{
qDebug() << evt->type();
if (evt->type() == QEvent::ChildPolished)
{
QChildEvent *child_ev = static_cast(evt);
childObj = child_ev->child();
if (childObj)
{
childObj->installEventFilter(this);
}
}
return QWebEngineView::event(evt);
}
bool eventFilter(QObject *obj, QEvent *ev)
{
if (obj == childObj
&& (ev->type() == QEvent::MouseButtonPress
|| ev->type() == QEvent::MouseButtonDblClick))
{
return true;
}
return QWebEngineView::eventFilter(obj, ev);
}
private:
QObject *childObj = NULL;
};
#endif // CUSTOMWEBVIEW_H