# -*- coding: utf-8 -*-
# python:2.x
__author__ = ‘Administrator‘
from PyQt4.QtGui import *
from PyQt4.Qt import *
from PyQt4.QtCore import *
import sys
class Tree(QTableView):
def __init__(self,parnet=None,*args):
super(Tree,self).__init__(parnet,*args)
QTextCodec.setCodecForTr(QTextCodec.codecForName(‘utf-8‘))
mode1=QStandardItemModel()
mode1.setColumnCount(2)
mode1.setRowCount(2)
mode1.setHeaderData(0,Qt.Horizontal,(u‘姓名‘))
mode1.setHeaderData(1,Qt.Horizontal,(u‘成绩‘))
self.setModel(mode1)
mode1.setItem(0,0,QStandardItem(‘999‘))
mode1.setItem(1,0,QStandardItem(‘9‘))
mode1.setItem(0,1,QStandardItem(‘hehe‘))
mode1.setItem(1,1,QStandardItem(‘hehe1‘))
app =QApplication(sys.argv)
x = Tree()
x.show()
sys.exit(app.exec_())
如图:
pyqt QTableView例子学习
时间: 2024-10-14 20:00:29