'Python PyQt5 black window showing instead of transparent in Raspberry PI 4

I'm working on a Raspberry Pi 4 project and in this i have to create a transparent window, so I developed code using Python and PyQt5 and it was working perfectly but i needed to create documentation for that and i installed so many other unnecessary packages also so i thought i should format SD card and start from fresh OS, so i backuped code and formatted SD card but after reinstalling OS and pyqt5 when i executed same code the black window is appearing instead of transparent window. I'm attaching a test code of my project which should generate a transparent window but instead black window is appearing. this code was working perfectly previously and even i checked it in windows also and it work perfectly there but i'm not sure what is the issue with raspberry pi.

After format i installed latest Raspberry pi OS(32 bit) published on 2022-01-28. But i thought maybe it is because of new updated OS so tried other OS also which are published on 2021-10-30 and 2021-05-07. I tried Raspberry PI OS(64 bit) also but nothing worked.

i used following commands to install PyQt5 and other tools

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python3
sudo app-get install python3-pip
python3 -m pip install --upgrade pip setuptools wheels

sudo apt-get install python3-pyqt5
sudo apt-get install qtbase5-dev
sudo apt-get install qt5-default 
sudo apt-get install qtcreator
sudo apt-get install python3-qt5

sudo apt-get install qt5-default is not working on new rpi os and after searching for issue i found that name of package is changed and i have to use sudo apt-get install qt5-assistant so when i installed the latest os i used this command.

i tried this using pip3 install also but nothing is working out. I'm very depressed now like every thing was working good previously and one format and nothing is working. i'm not able to understand what is the issue.

This is the code I'm using for transparent window.


import sys
from PyQt5.QtWidgets import QApplication, QWidget
from  PyQt5 import QtCore
from PyQt5.QtGui import QIcon, QPainter, QBrush, QPen

class displayC(QWidget):

    def __init__(self, scene = None, frame = False, tint = True):
        app = QApplication(sys.argv)
        super().__init__()
        self.initUI()
        sys.exit(app.exec_())

    def initUI(self):
        self.setGeometry(300,300,300,200) 
        self.setWindowTitle("MyApp")

        #self.setWindowOpacity(.4)
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground, on = True)

        self.show()

if __name__ == '__main__':
    ex = displayC()
    while True:
        print("AA")


The black window appearing like this. enter image description here

This code is generating some warning message also but i remembered this kind of warning was generating previously also and I searched for this also but not able to solve the issue.

This is the warning message.

qt.qpa.xcb: QXcbConnection: XCB error: 148 (Unknown), sequence: 192, resource id: 0, major code: 140 (Unknown), minor code: 20 


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source