PyQt5基础学习-QSplitter(Qt.Horizontal)(水平拖动控件宽度) 1QSplitter().setSizes([设置拖动控件的宽度])

将水平或者垂直的布局修改为可以拖动长宽的布局

Splitter.py 

"""
拖动控件之间的边界(Splitter)
"""
import sys, math
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt

class Splitter(QWidget):
    def __init__(self):
        super(Splitter, self).__init__()
        self.initUI()

    def initUI(self):
        hbox = QHBoxLayout(self)
        self.setWindowTitle("QSplitter 例子")
        self.setGeometry(300, 300, 300, 200)

        topleft = QFrame()
        topleft.setFrameShape(QFrame.StyledPanel)

        bottom = QFrame()
        bottom.setFrameShape(QFrame.StyledPanel)
        
        #设置可拖动的布局为水平
        splitter1 = QSplitter(Qt.Horizontal)
        textedit = QTextEdit()
        splitter1.addWidget(topleft)
        splitter1.addWidget(textedit)
        #设置水平两个控件的宽
        splitter1.setSizes([200, 200])
        
        #设置可拖动的布局为垂直
        splitter2 = QSplitter(Qt.Vertical)
        splitter2.addWidget(splitter1)
        splitter2.addWidget(bottom)
        
        hbox.addWidget(splitter2)
        self.setLayout(hbox)


if __name__ == "__main__":
    app = QApplication(sys.argv)

    main = Splitter()
    main.show()
    sys.exit(app.exec_())

PyQt5基础学习-QSplitter(Qt.Horizontal)(水平拖动控件宽度) 1QSplitter().setSizes([设置拖动控件的宽度])

 

上一篇:Python数据结构5:栈,代码实现栈,括号匹配算法,中缀表达式转后缀表达式算法,后缀表达式求值算法


下一篇:MVC项目报错NoSuchMethodError:org.springframework.context.support.AbstractApplicationContext.clearResourc