PyQt5 QSplitter控件应用

from PyQt5.QtWidgets import QFrame, QGridLayout, QVBoxLayout, QApplication, QHBoxLayout, QSplitter, QTextEdit, QPushButton, QLineEdit
from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt

class RadioButton(QtWidgets.QWidget):
    def __init__(self):
        QtWidgets.QWidget.__init__(self)
        self.setUI()
    def setUI(self):
        '''button'''
        self.btn1 = QPushButton('button1')
        self.btn2 = QPushButton('button2')
        self.btn3 = QPushButton('button3')
        self.btn4 = QPushButton('button4')
        self.grid = QGridLayout()
        self.grid.addWidget(self.btn1, 0, 0)
        self.grid.addWidget(self.btn2, 0, 1)
        self.grid.addWidget(self.btn3, 1, 0)
        self.grid.addWidget(self.btn4, 1, 1)
        '''lineEdit'''
        self.lineEdit1 = QLineEdit()
        self.lineEdit1.setText('lineEdit1')
        self.lineEdit2 = QLineEdit()
        self.lineEdit2.setText('lineEdit2')
        self.lineEdit3 = QLineEdit()
        self.lineEdit3.setText('lineEdit3')
        self.lineEdit4 = QLineEdit()
        self.lineEdit4.setText('lineEdit4')
        self.hboxLayout1 = QHBoxLayout()
        self.hboxLayout1.addWidget(self.lineEdit1)
        self.hboxLayout1.addWidget(self.lineEdit2)
        self.hboxLayout2 = QHBoxLayout()
        self.hboxLayout2.addWidget(self.lineEdit3)
        self.hboxLayout2.addWidget(self.lineEdit4)
        self.vboxLayout = QVBoxLayout()
        self.vboxLayout.addLayout(self.hboxLayout1)
        self.vboxLayout.addLayout(self.hboxLayout2)
        self.frame1 = QFrame()
        self.frame1.setLayout(self.vboxLayout)
        '''textEdit'''
        self.textedit1 = QTextEdit()
        self.textedit1.setText('textEdit1')
        self.textedit2 = QTextEdit()
        self.textedit2.setText('textEdit2')
        self.textedit3 = QTextEdit()
        self.textedit3.setText('textEdit3')
        self.textedit4 = QTextEdit()
        self.textedit4.setText('textEit4')
        self.frame2 = QFrame(self)
        self.frame2.setStyleSheet("background-color:green;")
        self.frame2.setLayout(self.grid)
        sp1 = QSplitter(Qt.Horizontal)
        sp1.addWidget(self.textedit1)
        sp1.addWidget(self.textedit2)
        sp2 = QSplitter(Qt.Horizontal)
        sp2.addWidget(self.frame1)
        sp3 = QSplitter(Qt.Horizontal)
        sp3.addWidget(self.frame2)
        sp4 = QSplitter(Qt.Vertical)
        sp4.addWidget(self.textedit3)
        sp4.addWidget(self.textedit4)
        self.hbox1 = QHBoxLayout()
        self.hbox2 = QHBoxLayout()
        self.vbox = QVBoxLayout()
        self.hbox1.addWidget(sp1)
        self.hbox1.addWidget(sp2)
        self.hbox2.addWidget(sp3)
        self.hbox2.addWidget(sp4)
        self.vbox.addLayout(self.hbox1)
        self.vbox.addLayout(self.hbox2)
        self.setLayout(self.vbox)

if __name__ == "__main__":
    import sys

    app = QApplication(sys.argv)
    qb = RadioButton()
    qb.show()
    sys.exit(app.exec_())

当 QSplitter中嵌套QSplitter时,可实现QSplitter与QSplitter之间拉动边框调节大小比重

from PyQt5.QtWidgets import QFrame, QGridLayout, QVBoxLayout, QApplication, QHBoxLayout, QSplitter, QTextEdit, QPushButton, QLineEdit
from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt

class RadioButton(QtWidgets.QWidget):
    def __init__(self):
        QtWidgets.QWidget.__init__(self)
        self.setUI()
    def setUI(self):
        '''button'''
        self.btn1 = QPushButton('button1')
        self.btn2 = QPushButton('button2')
        self.btn3 = QPushButton('button3')
        self.btn4 = QPushButton('button4')
        self.grid = QGridLayout()
        self.grid.addWidget(self.btn1, 0, 0)
        self.grid.addWidget(self.btn2, 0, 1)
        self.grid.addWidget(self.btn3, 1, 0)
        self.grid.addWidget(self.btn4, 1, 1)
        '''lineEdit'''
        self.lineEdit1 = QLineEdit()
        self.lineEdit1.setText('lineEdit1')
        self.lineEdit2 = QLineEdit()
        self.lineEdit2.setText('lineEdit2')
        self.lineEdit3 = QLineEdit()
        self.lineEdit3.setText('lineEdit3')
        self.lineEdit4 = QLineEdit()
        self.lineEdit4.setText('lineEdit4')
        self.hboxLayout1 = QHBoxLayout()
        self.hboxLayout1.addWidget(self.lineEdit1)
        self.hboxLayout1.addWidget(self.lineEdit2)
        self.hboxLayout2 = QHBoxLayout()
        self.hboxLayout2.addWidget(self.lineEdit3)
        self.hboxLayout2.addWidget(self.lineEdit4)
        self.vboxLayout = QVBoxLayout()
        self.vboxLayout.addLayout(self.hboxLayout1)
        self.vboxLayout.addLayout(self.hboxLayout2)
        self.frame1 = QFrame()
        self.frame1.setLayout(self.vboxLayout)
        '''textEdit'''
        self.textedit1 = QTextEdit()
        self.textedit1.setText('textEdit1')
        self.textedit2 = QTextEdit()
        self.textedit2.setText('textEdit2')
        self.textedit3 = QTextEdit()
        self.textedit3.setText('textEdit3')
        self.textedit4 = QTextEdit()
        self.textedit4.setText('textEit4')
        self.frame2 = QFrame(self)
        self.frame2.setStyleSheet("background-color:green;")
        self.frame2.setLayout(self.grid)
        sp1 = QSplitter(Qt.Horizontal)
        sp1.addWidget(self.textedit1)
        sp1.addWidget(self.textedit2)
        sp2 = QSplitter(Qt.Horizontal)
        sp2.addWidget(self.frame1)
        sp3 = QSplitter(Qt.Horizontal)
        sp3.addWidget(self.frame2)
        sp3.addWidget(sp2)
        sp4 = QSplitter(Qt.Vertical)
        sp4.addWidget(self.textedit3)
        sp4.addWidget(self.textedit4)
        sp4.addWidget(sp3)
        self.hbox1 = QHBoxLayout()
        self.hbox2 = QHBoxLayout()
        self.vbox = QVBoxLayout()
        self.hbox1.addWidget(sp1)
        # self.hbox1.addWidget(sp2)
        # self.hbox2.addWidget(sp3)
        self.hbox2.addWidget(sp4)
        self.vbox.addLayout(self.hbox1)
        self.vbox.addLayout(self.hbox2)
        self.setLayout(self.vbox)

if __name__ == "__main__":
    import sys

    app = QApplication(sys.argv)
    qb = RadioButton()
    qb.show()
    sys.exit(app.exec_())

效果: 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值