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_())
效果: