On the Layout of pyqt5 in QMainWindow
- 2021-06-29 11:20:35
- OfStack
Introduction:
If the parent class QMainWindow is used in pyqt5, the layout class, QGridLayout, QHBoxLayout, QVBoxLayout, is not useful in it.
Solve:
It is useful to use these three layout classes in a custom class that uses QWidget as its parent, but write a few more sentences when using QMainWindow.Specifically as follows:
widget = QWidget()
widget.setLayout(gridLayout)
self.setCentralWidget(widget)
Where do these sentences go?After your layout statement, where gridLayout refers to
gridLayout = QGridLayout(self)
With these words, it is used as in QWidget.