PyQt 4.2 QAbstractTableModel/QTableView Example

This is my OLD blog. I've copied this post over to my NEW blog at:

You should be redirected in 2 seconds.

from PyQt4.QtCore import * 
from PyQt4.QtGui import *
import sys

my_array = [['00','01','02'],

def main():
app = QApplication(sys.argv)
w = MyWindow()

class MyWindow(QWidget):
def __init__(self, *args):
QWidget.__init__(self, *args)

tablemodel = MyTableModel(my_array, self)
tableview = QTableView()

layout = QVBoxLayout(self)

class MyTableModel(QAbstractTableModel):
def __init__(self, datain, parent=None, *args):
QAbstractTableModel.__init__(self, parent, *args)
self.arraydata = datain

def rowCount(self, parent):
return len(self.arraydata)

def columnCount(self, parent):
return len(self.arraydata[0])

def data(self, index, role):
if not index.isValid():
return QVariant()
elif role != Qt.DisplayRole:
return QVariant()
return QVariant(self.arraydata[index.row()][index.column()])

if __name__ == "__main__":

No comments:


This is my *OLD* blog. I've copied all of my posts and comments over to my NEW blog at:

Please go there for my updated posts. I will leave this blog up for a short time, but eventually plan to delete it. Thanks for reading.