0

I'm using python 3.6.5 and PyQt 5.10.1.

I was trying with this simple code to have background transparency and after to add this feature to qutebrowser.

https://github.com/Rhylx/browser_bg_transparency

But it doesn't work. I have a webpage with a white background. Have someone an idea or a clue that could help me to fix it ?
Do you think it could be done with QWebEnginePage ?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Rhylx
  • 1
  • 2

1 Answers1

0

Try it:

import sys
import argparse

from PyQt5.QtCore import Qt
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView

def parse_args():
    """Parse commandline arguments."""
    parser = argparse.ArgumentParser()
    parser.add_argument('url', help='The URL to open')
    return parser.parse_known_args()[0]

if __name__ == '__main__':
    args = parse_args()
    app = QApplication(sys.argv)
    wv = QWebEngineView()

    wv.loadStarted.connect(lambda: print("Loading started"))
    wv.loadProgress.connect(lambda p: print("Loading progress: {}%".format(p)))
    wv.loadFinished.connect(lambda: print("Loading finished"))
    wv.setWindowFlags(Qt.FramelessWindowHint)
    wv.setAttribute(Qt.WA_TranslucentBackground, True)
    #wv.setStyleSheet("background:transparent;")

    wv.load(QUrl.fromUserInput(args.url))

    wv.setWindowOpacity(0.6)                                  # +++
    wv.setWindowFlags(Qt.WindowStaysOnBottomHint)             # +++

    wv.show()

    app.exec_()

test.html

<!DOCTYPE html>
<html>
    <head>
        <style>
        body {
            background-color: rgba(255,0,0,255);
            color: blue;
            font-size: 36px;
        }
        </style>
    </head>
    <body>
        HELLO WORLD !!
    </body>
</html>

enter image description here

S. Nick
  • 12,879
  • 8
  • 25
  • 33
  • Ok thanks for your answer. The problem with that is that the entire page becomes transparent (even the content, here : Hello World !!). Is it possible to have only the background transparent ? – Rhylx Jul 04 '18 at 05:33
  • Haven't you "Hello World !!" transparent? – Rhylx Jul 04 '18 at 17:50