其他分享
首页 > 其他分享> > PyQt5基础学习-QSplitter(Qt.Horizontal)(水平拖动控件宽度) 1QSplitter().setSizes([设置拖动控件的宽度])

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_())

 

标签:__,控件,splitter1,Splitter,拖动,self,宽度,addWidget
来源: https://www.cnblogs.com/hyq-lst/p/15866299.html