QWidget::setLayout: Attempting to set QLayout "" on MainWindow "", which already has a layout
You can't set a QLayout
directly on the QMainWindow
. You need to create a QWidget
and set it as the central widget on the QMainWindow
and assign the QLayout
to that.
wid = QtGui.QWidget(self)
self.setCentralWidget(wid)
layout = QtGui.QVBoxLayout()
wid.setLayout(layout)
Just an update to Brenden Abel's answer:
QWidget and QVBoxLayout (for Python3, PyQt5) are now contained in the PyQt5.QtWidgets module and not the PyQt5.QtGui module.
So updated code:
wid = QtWidgets.QWidget(self)
self.setCentralWidget(wid)
layout = QtWidgets.QVBoxLayout()
wid.setLayout(layout)