I have a custom widget called GraphCanvas which inherits from QWidget, it is functional but when I try to use it in a window object and set a background color to it, it does not work. The main issue is I'm making a frameless transparent window, and when I do this the actual GraphCanvas becomes transparent as well and I can't find out why.
Minimal reproducible example:
from PyQt5.QtWidgets import QWidget, QApplication
from PyQt5.QtCore import Qt
from Custom_Widgets.CanvasWidget.GraphCanvas import GraphCanvas
import sys
class Window(QWidget):
def __init__(self):
QWidget.__init__(self)
self.setGeometry(100, 100, 500, 500)
flags = Qt.WindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
self.setWindowFlags(flags)
self.canvas = GraphCanvas(self)
self.canvas.setGeometry(0, 0, 500, 500)
self.canvas.setStyleSheet('background-color: grey;')
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
class GraphCanvas(QWidget):
def __init__(self, parent):
super().__init__(parent)
In the Window
__init__
if I change GraphCanvas(self)
to QWidget(self)
it works correctly, otherwise the GraphCanvas for some reason inherits the transparent background and nothing shows up.