qt - How can I get paint events with QtWebEngine? -


i extended qwebengineview.

#ifndef myqwebengineview_h #define myqwebengineview_h #include <qwebengineview> class myqwebengineview : public qwebengineview { public:     myqwebengineview(qwidget *parent = 0);     ~myqwebengineview(); protected:     virtual void paintevent(qpaintevent *); }; #endif // myqwebengineview_h 

but can't paintevent(qpaintevent *) called.

#include "myqwebengineview.h" #include <qpaintevent> #include <qpainter> #include <qwebengineview> #include <qwidget>  myqwebengineview::myqwebengineview(qwidget *parent):qwebengineview(parent) {     qdebug() << "myqwebengineview(" << parent << ")";     qdebug() << "qt::wa_paintonscreen: " << testattribute(qt::wa_paintonscreen);     //setattribute(qt::wa_paintonscreen, true); } myqwebengineview::~myqwebengineview() { } void myqwebengineview::paintevent(qpaintevent * event) {     qdebug() << "paintevent(" << event << ")";     qwebengineview::paintevent(event);     //qwidget::paintevent(event);      qdebug() << event->rect();     qdebug() << event->region(); } 

can please tell me what's wrong?

unfortunately widget qwebengineview not catch events (except mouse enter , exit, added keyboard events), example see "[qtbug-43602] webengineview not handle mouse events".

almost events (like mouse move or paint) handled qwebengineview child delegate of private type renderwidgethostviewqtdelegatewidget derived qopenglwidget.

it possible catch new child of qwebengineview of type qopenglwidget , install on child event filter hook needed events.

that solution relies on undocumented structure of qwebengineview. may not supported future qt releases. however, usable projects current qt versions. maybe in future more convenient interface catch qwebengineview events implemented.

the following subclass of qwebengineview implements that:

#ifndef webengineview_h #define webengineview_h  #include <qevent> #include <qchildevent> #include <qpointer> #include <qopenglwidget> #include <qwebengineview> #include <qpaintevent>  class webengineview : public qwebengineview {     q_object  private:     qpointer<qopenglwidget> child_;  protected:     bool eventfilter(qobject *obj, qevent *ev)     {         // emit delegatepaint on paint event of last added qopenglwidget child         if (obj == child_ && ev->type() == qevent::paint) {             qpaintevent *pe = static_cast<qpaintevent*>(ev);             // paint event             // ...             // or emit signal notify other objects             emit delegatepaint(pe);         }          return qwebengineview::eventfilter(obj, ev);     }  public:     webengineview(qwidget *parent = nullptr) :         qwebengineview(parent), child_(nullptr)     {     }      bool event(qevent * ev)     {         if (ev->type() == qevent::childadded) {             qchildevent *child_ev = static_cast<qchildevent*>(ev);              // there qobject child should ignored here;             // use qopenglwidget child             qopenglwidget *w = qobject_cast<qopenglwidget*>(child_ev->child());             if (w) {                 child_ = w;                 w->installeventfilter(this);             }         }          return qwebengineview::event(ev);     }  signals:     void delegatepaint(qpaintevent*); };  #endif // webengineview_h 

child adding caught webengineview::event. child pointer saved , event filter installed on child. on child paint event signal webengineview::delegatepaint(qpaintevent*) emitted in webengineview::eventfilter.

the signal delegatepaint emitted when web view changed script or highlighting of web controls due mouse hover or other reason.

note not same overriding qwebengineview::paintevent. in way possible receive notification changed.

so, possible react on event directly in webengineview::eventfilter or connect signal delegatepaint notify other objects web view repainting, example see qt qwebengine render after scrolling?


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

node.js - Using Node without global install -

php - CakePHP HttpSockets send array of paramms -