How can I get paint events with QtWebEngine?

后端 未结 2 1092
我在风中等你
我在风中等你 2020-12-30 17:51

I extended QWebEngineView.

#ifndef MYQWEBENGINEVIEW_H
#define MYQWEBENGINEVIEW_H
#include 

        
2条回答
  •  悲&欢浪女
    2020-12-30 17:56

    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
    

提交回复
热议问题