测试用

import sys
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import *

from testqt import QJsonModel


class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.resize(800,600)
        # 窗体设置
        self.setWindowTitle("test")
        # 菜单动作
        self.exitAct = QAction(QIcon('exit.png'), '&Exit', self)
        self.exitAct.setShortcut('Ctrl+Q')
        self.exitAct.setStatusTip("save")
        self.exitAct.triggered.connect(self.quitAction)
        # 菜单栏
        self.menu = self.menuBar()
        self.menu.setNativeMenuBar(False)
        self.fileMenu = self.menu.addMenu('File')
        self.fileMenu.addAction(self.exitAct)
        # 中心窗口嵌入widget布局
        self.view = QTreeView()
        self.model = QJsonModel()

        self.view.setModel(self.model)


        self.lineEdit1 = QLineEdit()

        self.textEdit1 = QTextEdit()


        self.gridlayout = QGridLayout()
        self.gridlayout.addWidget(self.view,0,0)
        self.gridlayout.addWidget(self.textEdit1,1,0)
        self.gridlayout.setRowStretch(0,3)
        self.gridlayout.setRowStretch(1,1)


        self.widGet = QWidget()
        self.widGet.setLayout(self.gridlayout)
        self.setCentralWidget(self.widGet)
        self.center()

    # 窗口居中
    def center(self):
        self.size = QDesktopWidget().screenGeometry()
        self.resize = self.geometry()
        self.move((self.size.width() - self.resize.width()) / 2, (self.size.height() - self.resize.height()) / 2)

    def quitAction(self):
        self.model.load("./load.json")
        self.view.setModel(self.model)


        # self.lineEdit1 = QLineEdit()
        #
        # self.textEdit1 = QTextEdit()
        #
        # self.vbox1 = QVBoxLayout()
        # self.vbox1.addWidget(self.view)
        # self.vbox1.addWidget(self.textEdit1)
        #
        # self.gridlayout = QGridLayout()
        # self.gridlayout.addItem(self.vbox1, 0, 0)
        #
        # self.widGet = QWidget()
        # self.widGet.setLayout(self.gridlayout)
        # self.setCentralWidget(self.widGet)
        # self.center()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    mainWindow = MainWindow()
    mainWindow.show()
    sys.exit(app.exec_())

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页