I'm doing a desktop app where I made multiple classes inherit from QWidget, and the problem is that when I try to apply color to the background of each one, it doesn't seem to be working.
I expect a black background of the main app and a white background for the apps (which contains other widgets but for now I'm just figuring out the background), but instead I get a totally black window.
class Main(QMainWindow):
def __init__(self):
super().__init__()
self.main_widget = QWidget(self)
self.setCentralWidget(self.main_widget)
self.main_widget.setStyleSheet('background-color: black')
self.LO = QVBoxLayout(self.main_widget)
self.square1 = Square()
self.square2 = Square()
self.LO.addWidget(self.square1)
self.LO.addWidget(self.square2)
class Square(QWidget):
def __init__(self):
super().__init__()
self.setStyleSheet('background-color: #FFFFFF')
if __name__ == '__main__':
app = QApplication(sys.argv)
mainWin = Main()
mainWin.show()
sys.exit(app.exec_())
This is what I expect to happen (background black, widget white):