2

If you have a compositing window manager, this will give you a transparent window:

import PyQt4.QtGui
a = PyQt4.QtGui.QApplication([])
import PyQt4.QtCore
import PyQt4.QtWebKit
w = PyQt4.QtWebKit.QWebView()
w.setAttribute(PyQt4.QtCore.Qt.WA_TranslucentBackground)
w.show()
a.exec_()

But this will not have a transparent window:

import PyQt4.QtGui
a = PyQt4.QtGui.QApplication([])
import PyQt4.QtCore
import PyQt4.QtWebKit
w = PyQt4.QtWebKit.QWebView()
w.setAttribute(PyQt4.QtCore.Qt.WA_TranslucentBackground)
w.page().currentFrame().documentElement().setInnerXml("text")
w.show()
a.exec_()

I want to be able to have text floating over the background... Is this possible?

Dave Butler
  • 1,646
  • 1
  • 12
  • 18

2 Answers2

0

The problem here is lazy instantiation. Initially, the WebKit view is not instantiated, and so you get a transparent background. As soon as you access w.page(), the WebKit view is actually instantiated, and so the default white background appears. I am not aware of any way of getting transparency then from inside the WebKit view; there may be a way, but it's not "normal web stuff". For example, w.page().currentFrame().documentElement().setInnerXml('<style>html,body{background:transparent}</style>') doesn't help: the default of white is rendered underneath the transparency.

Possible help: Is it possible to render web content over a clear background using WebKit?

Community
  • 1
  • 1
Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
0

This seems to work:

from PyQt4 import QtGui, QtWebKit
from PyQt4.QtCore import Qt
a = QtGui.QApplication([])
view = QtWebKit.QWebView()
view.setAttribute(Qt.WA_TranslucentBackground)
# Works with and without that following line
view.setAttribute(Qt.WA_OpaquePaintEvent, False)
page = view.page()
palette = page.palette()
palette.setBrush(QtGui.QPalette.Base, Qt.transparent)
page.setPalette(palette)
page.currentFrame().documentElement().setInnerXml("text")
view.show()
a.exec_()

Source: http://labs.qt.nokia.com/2009/06/30/transparent-qwebview-or-qwebpage/

aukaost
  • 3,778
  • 1
  • 24
  • 26