如下所示:
import sys
from PyQt5 import QtCore,QtGui
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.uic import loadUi
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
loadUi('qtdesigner.ui', self)
self.pushButton.clicked.connect(self.say)
self.showData()
def say(self):
self.label.setText("哈哈哈")
print("哈哈哈")
def showData(self):
# 准备数据模型
self.sm=QtGui.QStandardItemModel()
#设置数据头栏名称
self.sm.setHorizontalHeaderItem(0, QtGui.QStandardItem("Name"))
self.sm.setHorizontalHeaderItem(1, QtGui.QStandardItem("NO."))
#设置数据条目
self.sm.setItem(0, 0, QtGui.QStandardItem("张三"))
self.sm.setItem(0, 1, QtGui.QStandardItem("20120202"))