凌的博客

您现在的位置是: 首页 > 学无止境 > python > 

python

29. PyQt6 QSplitter

2023-10-17 python 691
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QHBoxLayout, QFrame, QSplitter, QWidget
from PyQt6.QtGui import QGuiApplication
from PyQt6.QtCore import Qt


class App(QMainWindow):

    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle("PyQt6 QSplitter")

        hbox = QHBoxLayout()

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

        topright = QFrame()
        topright.setFrameShape(QFrame.Shape.StyledPanel)

        bottom = QFrame()
        bottom.setFrameShape(QFrame.Shape.StyledPanel)

        splitter1 = QSplitter(Qt.Orientation.Horizontal)
        splitter1.addWidget(topleft)
        splitter1.addWidget(topright)

        splitter2 = QSplitter(Qt.Orientation.Vertical)
        splitter2.addWidget(splitter1)
        splitter2.addWidget(bottom)

        hbox.addWidget(splitter2)

        w = QWidget()
        w.setLayout(hbox)
        self.setCentralWidget(w)

        self.setGeometry(100, 100, 400, 300)
        self.center()

    def center(self):
        qr = self.frameGeometry()
        cp = QGuiApplication.primaryScreen().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())


if __name__ == "__main__":
    app = QApplication(sys.argv)
    cls_app = App()
    cls_app.show()
    sys.exit(app.exec())


image.png

文章评论

0条评论