[SOLVED] extending QWebView to post process/filter the web page



  • 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?



  • 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.



  • 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();
    @



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.