PyQt5 must learn QSplitter every day to implement window separation

不言
Release: 2018-04-19 10:35:08
Original
3884 people have browsed it

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_())
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template