PyQt5: A custom subclass of QWidget cannot fill entire window, but QWidget() can, what's the difference?

32 Views Asked by At

class customWidget(QWidget): def init(self, parent=None): super(customWidget, self).init(parent)

class Window1(QWidget): def init(self): super(Window1, self).init() self.setFixedSize(800, 600) self.initUI()

def initUI(self):
    vbox = QVBoxLayout()
    a = customWidget(self)
    a.setStyleSheet("background-color: red;")
    vbox.addWidget(a)
    self.setLayout(vbox)

enter image description here class Window2(QWidget): def init(self): super(Window2, self).init() self.setFixedSize(800, 600) self.initUI()

def initUI(self):
    vbox = QVBoxLayout()
    a = QWidget(self)
    a.setStyleSheet("background-color: red;")
    vbox.addWidget(a)
    self.setLayout(vbox)

enter image description here

what's the difference between fig1 and fig2, how can i make the same effect in window with window2

0

There are 0 best solutions below