1 import sys 2 from pyqt5.qtwidgets import (qapplication, 3 qwidget, 4 qsplitter, 5 qtextedit, 6 qpushbutton, 7 qlabel) 8 from pyqt5.qtcore import (QT, qsettings) 9 10 11 class window (qwidget): 12 def _ init _ (self, parent = none): 13 super (window, self ). _ init _ (parent, flags = QT. window) 14 15 # create a split window with the parent control as window: 16 splitter_0 = qsplitter (Self) 17 # Set the control in the split window to be collapsed: 18 splitter_0.setchildrencollapsible (false) 19 # Set the split width: 20 splitter_0.sethandlewidth (35) 21 # Set the split window size: 22 splitter_0.resize (600,450) 23 24 splitter_0.addwidget (qtextedit ()) 25 26 # create a split window whose parent control is splitter_0: 27 splitter_1 = qsplitter (splitter_0) 28 # set the direction of the split window: 29 splitter_1.setorientation (QT. horizontal) 30 # Add a control for the split window: 31 splitter_1.addwidget (qtextedit ('Arrange horizontally ') 32 splitter_1.addwidget (qtextedit ('Arrange horizontally ')) 33 splitter_1.addwidget (qtextedit ('horizontally arranged ') 34 # Set the width of the control in the split window. If it is vertically arranged, it is the height: 35 splitter_1.setsizes ([120, 80, 60]) 36 # Set whether to move the separator bar with the mouse: 37 splitter_1.setopaqueresize (false) 38 39 # create a split window with the parent control splitter_0 and Vertical Split: 40 splitter_2 = qsplitter (QT. vertical, splitter_0) 41 # insert controls for split windows: 42 splitter_2.insertwidget (0, qtextedit ('vertically arranged ') 43 splitter_2.insertwidget (1, qtextedit ('vertically arranged ')) 44 # Set the proportion of controls in the Split Window Based on ID: 45 splitter_2.setstretchfactor (0, 1) 46 splitter_2.setstretchfactor (1, 3) 47 # Set whether controls in the split window can be folded Based on ID: 48 splitter_2.setcollapsible (0, false) 49 splitter_2.setcollapsible (1, true) 50 51 self. show () 52 53 54 if _ name _ = "_ main _": 55 APP = qapplication (sys. argv) 56 window = window () 57 sys.exit(app.exe C _())
The interface is shown in the following figure:
Animation effect demonstration:
[Pyqt5 learning records] 010: qsplitter