[SOLVED] extending QWebView to post process/filter the web page
-
wrote on 20 Apr 2014, 02:17 last edited by
so I know how to extend QWebView and to override paintEvent if I wanted to draw something completely different.
But instead, I want to grab the content of the web-view (or whatever widget for that matter) - do something to it (ie. filter/process) and then display the result instead of what would have been drawn had I not overridden it... but I find that if I do any of the QWidget grabbing functions within paintEvent, I get recursion and crashes.What's the right way?
-
wrote on 21 Apr 2014, 07:27 last edited by
Have a look at QWidget::render() function. you can use that function to get the rendering a pixmap, process it and paint it into widgets rectangle.
-
wrote on 21 Apr 2014, 12:08 last edited by
I tried using render() as below, but only get a black image (and it seems like render() actually calls into paintEvent as well.
@
QPixmap pixmap(size());
QPainter painter;painter.begin(&pixmap);
this->render(&painter);
painter.end();// processing/filtering would go here.
painter.begin(this);
painter.drawPixmap(0, 0, pixmap);
painter.end();
@ -
wrote on 30 Apr 2014, 19:11 last edited by
I did end up getting this to work by using two widgets.. I extended QWebView and overrode paintEvent to grab the widget and process it, and a second QFrame, occupying the same visual space, with transparent to mouse/keyboard events, extended to override paintEvent to draw the QImage as saved by the QWebView.