[webkit-qt] WebView with Transparent Background

Michael Ditum mike at mikeditum.co.uk
Fri Nov 12 13:52:54 PST 2010


On Mon, Nov 8, 2010 at 7:27 PM, Michael Ditum <mike at mikeditum.co.uk> wrote:

> On Mon, Nov 8, 2010 at 7:21 PM, Ariya Hidayat <ariya.hidayat at gmail.com>wrote:
>
>> > I'm currently trying to get a webkit widget with a transparent
>> background so
>> > that if, in an HTML document, the html and body nodes are styled to have
>> > their background-color set to transparent then the Widgets behind the
>> > WebView Widget are visible through.
>>
>> Here is what I wrote a looong time ago (still the first hit of
>> googling for 'transparent qwebview'):
>>
>> http://labs.qt.nokia.com/2009/06/30/transparent-qwebview-or-qwebpage/
>>
>> See if it works for you.
>>
>
> Thank you that's exactly what I wanted, works brilliantly! Turns out my
> google-fu is not as strong as I thought.
>
> Hi,

I've been playing with this a bit more and have come across another problem
which has stumped me. I'm trying to have the QWebView render on top of a
video window rendered with vlc so the video is visible through the
transparent elements. However the QWebView is obstructing the video. If I
swap the QVlcPlayer for a QTextEdit then it displays fine so it must be
something with my custom widget but I'm lost to even know where to start
looking. Any help would be greatly appreciated!

Here's my Qt VLC code in QVlcPlayer.h...

#ifndef QVLC_PLAYER_H
#define QVLC_PLAYER_H

#include <vlc/vlc.h>
#include <QWidget>

class QVlcPlayer : public QWidget
{
Q_OBJECT
libvlc_instance_t *_vlcinstance;
libvlc_media_player_t *_mp;
libvlc_media_t *_m;

public:
QVlcPlayer(QWidget *widget = 0) : QWidget(widget)
{
const char * const vlc_args[] = {
"-I", "dummy", "--ignore-config", "--extraintf=logger", "--verbose=2",
"--plugin-path=plugins"
};
_vlcinstance=libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
_mp = libvlc_media_player_new (_vlcinstance);
}

~QVlcPlayer()
{
libvlc_media_player_stop (_mp);
libvlc_media_player_release (_mp);
libvlc_release (_vlcinstance);
}

public slots:
void playFile(QString file)
{
_m = libvlc_media_new_location (_vlcinstance, file.toAscii());
libvlc_media_player_set_media (_mp, _m);
#if defined(Q_OS_WIN)
libvlc_media_player_set_hwnd(_mp, this->winId()); // for vlc 1.0
#elif defined(Q_OS_MAC)
libvlc_media_player_set_agl (_mp, this->winId()); // for vlc 1.0
#else //Linux
libvlc_media_player_set_xwindow(_mp, this->winId()); // for vlc 1.0
#endif
libvlc_media_player_play (_mp);
}
};
#endif

and my main.cpp code...

#include "QVlcPlayer.h"
#include <QApplication>
#include <QWebView>
#include <QWebSettings>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QWidget window;
window.resize(1280, 720);

QVlcPlayer player(&window);
player.setGeometry(0, 0, 1280,720);
player.playFile("udp://@239.71.0.0:1234");

QWebView *view = new QWebView(&window);

QPalette pal = view->palette();
pal.setBrush(QPalette::Base, Qt::transparent);
view->page()->setPalette(pal);

view->setAttribute(Qt::WA_OpaquePaintEvent, false);
view->load(QUrl("test.html"));
view->setGeometry(10, 10, 1260, 680);

window.show();

return a.exec();
}

Thanks in advance!

Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-qt/attachments/20101112/3b43b709/attachment.html>


More information about the webkit-qt mailing list