Talking about the layout of pyqt5 in QMain Windows

Time:2019-8-10

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.

Recommended Today

Manjaro uses SS method (requires nodejs environment)

Just installed manjaro, need to installshadowsocks-qt5+Proxy SwitchyOmega, but the latest Chrome has long blocked the installation of non Google store CRX channels. Here is my solution, which is troublesome but usable. If you are familiar with NPM commands in nodejs, you won’t find it troublesome, because nodejs is used for compilation. Preparation environment: A VPS […]