Transparent QWebView over Phonon VideoWidget



  • Hello everyone.
    I need put QWebView (ok, any QWidget) with transparent background over Phonon VideoWidget,

    I doing it so:
    @
    m_video = new Phonon::VideoWidget;
    .....
    QWebView *view = new QWebView(mVideo);
    view->setHtml("<div style="color:#FFFFFF;font-size:36px;">Hello Qt!</div>");

    QPalette palette = view->page()->palette();
    palette.setBrush(QPalette::Base, Qt::transparent);
    view->setPalette(palette);
    
    view->setAttribute(Qt::WA_OpaquePaintEvent, false);
    
    m_video->show();
    m_video->resize(640, 480);
    
    view->setFixedSize(m_video->width(), m_video->height());
    

    @

    But I'm not see video under white text, I just see white text on black rectangle.
    Of course, without overlay widget I see video normally.

    Any suggestions?



  • I found workaround for this issue:

    This is subclass of Phonon::VideoWidget with overrided events methods.

    @class OverlayedVideoWidget : public Phonon::VideoWidget
    {
    public:
    OverlayedVideoWidget(QWidget *parent = 0) :
    Phonon::VideoWidget(parent),
    m_overlayWidget(0)
    {
    }

    void setOverlayWidget(QWidget *widget)
    {
        m_overlayWidget = widget;
    }
    

    protected:
    void moveEvent(QMoveEvent *event)
    {
    if (m_overlayWidget)
    m_overlayWidget->move(event->pos());
    }

    void resizeEvent(QResizeEvent *event)
    {
        if (m_overlayWidget)
            m_overlayWidget->resize(event->size());
    }
    
    void hideEvent(QHideEvent *)
    {
        if (m_overlayWidget)
            m_overlayWidget->hide();
    }
    
    void showEvent(QShowEvent *)
    {
        if (m_overlayWidget)
            m_overlayWidget->show();
    }
    
    void closeEvent(QCloseEvent *)
    {
        if (m_overlayWidget)
            m_overlayWidget->close();
    }
    

    private:
    QWidget *m_overlayWidget;
    };@

    Usage example:
    @m_video = new OverlayedVideoWidget;

    QWebView *view = new QWebView();
    view->setHtml("<div style="color:#FFFFFF;font-size:36px;">Hello Qt!</div>");
    QPalette palette = view->page()->palette();
    palette.setBrush(QPalette::Base, Qt::transparent);

    view->setPalette(palette);
    view->page()->setPalette(palette);
    view->setAttribute(Qt::WA_OpaquePaintEvent, false);
    view->setAttribute(Qt::WA_TranslucentBackground, true);
    view->setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint);

    m_video->setOverlayWidget(view);
    m_video->show();
    m_video->resize(640, 480);@

    Main idea of this workaround is set to overlayed widget ToolTip window flag and connect move, resize, etc events of both objects.



  • Hello Vass,

    I really like your solution, this is very smart! I would like to use it, but i have a QGLWidget instead of a QWebView. Is it possible to mark the QGLWidget as ToolTip and only have the OpenGL Objects on top and not the black background from the QGLWidget?

    btw I use Qt4.6



  • I guess it should work with QGLWidget too, because QGLWidget is subclass of QWidget, so technically it's possible and not difficult.



  • Hm seems that it does not work as easy as I thougt, would you give it a try ?



  • So, to answer my own question -> yes it is really easy. Just define Qt::WA_TranslucentBackground to true for your QGLWidget, show it as Tooltip and you will have a nice opengl overlay for your phonon video. Import to enable your composite manager, e.g. Compiz for Linux.



  • Hello once again,

    the solution works, but do you think there would be probably a better and cleaner solution ? (referring to http://stackoverflow.com/questions/4473709/play-a-video-with-custom-overlay-graphics/13120078#13120078)



  • bq. the solution works, but do you think there would be probably a better and cleaner solution ? (referring to http://stackoverflow.com/questions/4473709/play-a-video-with-custom-overlay-graphics/13120078#13120078)

    I am not sure if this solution is better or cleaner but it worked for me. Here is a complete code example, which finally worked after one day of trying...

    http://www.qtcentre.org/archive/index.php/t-39496.html

    Good Luck!


Log in to reply
 

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