PDA

View Full Version : QWebView transparent problem



embedyy
14th January 2009, 18:43
Hi all,
I want to have a transparent QWebView. Now, I can make a transprent window by this thread (http://www.qtcentre.org/forum/p-transparency-setmask-createheuristicmask-createmaskfromcolor-qpixmap-post28500/postcount4.html).
As I know, QWebView is a child of QWidget. But when I use webView->load(QUrl("http://www.google.com/"));, the window of QWebView is not transparent. Can I make the QWebView appear as text on the desktop? Anyone who can help me.
here is my code.



class WebView : public QWebView
{

public:
WebView()
{
pixmap = new QPixmap(size());
}
~WebView()
{
delete pixmap;
}
protected:
void resizeEvent(QResizeEvent* event)
{
QWebView::resizeEvent(event);
pixmap->fill(Qt::transparent);
QPainter::setRedirected(this, pixmap);
QPaintEvent pe(rect());
paintEvent(&pe);
QPainter::restoreRedirected(this);
setMask(pixmap->mask());//

}
private:
QPixmap* pixmap;
};
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
WebView* webView = new WebView();
QPalette palette = webView->palette();
webView->load(QUrl("http://www.google.com/"));

webView->show();
return a.exec();
}

naruto_9w
15th January 2009, 09:48
I've tried to set palette of webview, but the background turns out to be full transparent (nothing on the screen, totally transparent...), what's the problem, anybody help?



WebView() {
QPalette pal = palette();
pal.setBrush(QPalette::Window, Qt::transparent);
setPalette(pal);
}

naruto_9w
16th January 2009, 04:39
Anybody help? Thanks!

aamer4yu
16th January 2009, 05:19
Dont do anything,,, just use QWidget::setWindowOpacity
It will set the transparency for the whole widget.

naruto_9w
16th January 2009, 07:20
Dont do anything,,, just use QWidget::setWindowOpacity
It will set the transparency for the whole widget.

Thanks for your answer first!

The method you mentioned do be able to solve the transparency problem of a *whole* widget, nevertheless, our purpose is to leave the background transparent, while make the contents (for example, a button, an input, etc) opaque, somehow like the effect of Yahoo! desktop widget.

So any suggestion for these? Thanks!