I want to create a full-screen window with a translucent background, but fully visible child widgets (overlay effect view).
Here is what I still have:
import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * app = QApplication(sys.argv)
This creates a translucent effect, but even the button is translucent.
I also tried to substitute
window.setWindowOpacity(0.3)
with this challenge
window.setAttribute(Qt.WA_TranslucentBackground, True)
but to no avail, in this case the background was completely transparent (while the button was completely fully visible).
Solution: (implemented thanks to Aaronβs proposal) :
The trick is to implement a custom paintEvent for the main window.
import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * class CustomWindow(QMainWindow): def paintEvent(self, event=None): painter = QPainter(self) painter.setOpacity(0.7) painter.setBrush(Qt.white) painter.setPen(QPen(Qt.white)) painter.drawRect(self.rect()) app = QApplication(sys.argv)
source share