This article mainly introduces the window separation that must be learned every day in PyQt5. It has certain reference value. Interested friends can refer to it
QSplitter allows users to control the boundaries of sub-panels by dragging them. The size of the subpanel. In our example, we used two QSplitters to separate three QFrame controls.
#!/usr/bin/python3 # -*- coding: utf-8 -*- """ PyQt5 教程 这个例子说明如何使用QSplitter部件。 作者:我的世界你曾经来过 博客:http://blog.csdn.net/weiaitaowang 最后编辑:2016年8月4日 """ import sys from PyQt5.QtWidgets import (QApplication, QWidget, QHBoxLayout, QFrame, QSplitter) from PyQt5.QtCore import Qt class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): hbox = QHBoxLayout(self) topleft = QFrame(self) topleft.setFrameShape(QFrame.StyledPanel) topright = QFrame(self) topright.setFrameShape(QFrame.StyledPanel) bottom = QFrame(self) bottom.setFrameShape(QFrame.StyledPanel) splitter1 = QSplitter(Qt.Horizontal) splitter1.addWidget(topleft) splitter1.addWidget(topright) splitter2 = QSplitter(Qt.Vertical) splitter2.addWidget(splitter1) splitter2.addWidget(bottom) hbox.addWidget(splitter2) self.setLayout(hbox) self.setGeometry(300, 300, 300, 200) self.setWindowTitle('窗口分隔') self.show() if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())
In our example, we used three frame widgets and two QSplitters. Note that QSplitter boundaries may not be visible for some themes.
topleft = QFrame(self)
topleft.setFrameShape(QFrame.StyledPanel)
We add the StyledPanel style to the QFrame control to make the boundaries between QFrame controls more obvious.
splitter1 = QSplitter(Qt.Horizontal)
splitter1.addWidget(topleft)
splitter1.addWidget(topright)
We created a QSplitter control and added Two QFrames go in.
splitter2 = QSplitter(Qt.Vertical)
splitter2.addWidget(splitter1)
We can also add a splitter to another splitter widget. We can also add a QSplitter to In another QSplitter control.
After the program is executed
Related recommendations:
PyQt5 tool tip function that must be learned every day
The above is the detailed content of PyQt5 must learn QSplitter every day to implement window separation. For more information, please follow other related articles on the PHP Chinese website!