[PyQt5]高级控件8 - 网格布局QGridLayout

wuchangjian2021-11-09 06:47:22编程学习

文章目录

  • 效果图
  • 完整代码

效果图

gridlayout示例图

完整代码

import sys
from PyQt5.QtWidgets import *

class QGridLayoutDemo(QMainWindow):
    def __init__(self):
        super(QGridLayoutDemo, self).__init__()

        self.resize(400, 150)
        #设置窗口标题
        self.setWindowTitle("QGridLayoutDemo")

        titleLabel = QLabel('标题')
        authorLabel = QLabel('提交人')
        contentLabel = QLabel('申告内容')

        titleEdit = QLineEdit()
        authorEdit = QLineEdit()
        contentEdit = QTextEdit()

        layout = QGridLayout()
        layout.setSpacing(10)

        layout.addWidget(titleLabel, 1, 0)
        layout.addWidget(titleEdit, 1, 1)
        layout.addWidget(authorLabel, 2, 0)
        layout.addWidget(authorEdit, 2, 1)
        layout.addWidget(contentLabel, 3, 0)
        layout.addWidget(contentEdit, 3, 1, 5, 1)

        mainFrame = QWidget()
        mainFrame.setLayout(layout)
        self.setCentralWidget(mainFrame)

if  __name__ == '__main__':
    app = QApplication(sys.argv)
    main = QGridLayoutDemo()
    main.show()
    sys.exit(app.exec_())

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。