Introduction:
If the parent class is QMainWindow in pyqt5, the layout class, QGridLayout, QHBoxLayout and QVBoxLayout are not suitable for use.
Solve:
It’s good to use these three layout classes in a custom class with QWidget as its parent, but you need to write a few more sentences when using QMainWindow. As follows:
widget = QWidget()
widget.setLayout(gridLayout)
self.setCentralWidget(widget)
Where do these words go? After your layout statement, gridLayout refers to
gridLayout = QGridLayout(self)
Add these words and use them as well as in QWidget.
In this article, the layout of pyqt5 in QMainWindows is discussed. The editor has shared all the contents. I hope to give you a reference, and I hope you will support developpaer more.