import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
def __init__(self, parent=None):
self.m_data = [["1","2","3"],["4","5","6"],["7","8","9"]]
return len(self.m_data)
return len(self.m_data[0])
def data(self, index, role = Qt.DisplayRole):
if(not index.isValid()):
elif(role!=Qt.DisplayRole):
return QVariant(self.
m_data[index.
row()][index.
column()])
if __name__ == "__main__":
model = Model()
proxy.setSourceModel(model)
tv.setModel(proxy);
tv.show();
sys.exit(app.exec_())
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Model(QAbstractTableModel):
def __init__(self, parent=None):
QAbstractTableModel.__init__(self, parent)
self.m_data = [["1","2","3"],["4","5","6"],["7","8","9"]]
def rowCount(self, parent=QModelIndex()):
return len(self.m_data)
def columnCount(self, parent=QModelIndex()):
return len(self.m_data[0])
def data(self, index, role = Qt.DisplayRole):
if(not index.isValid()):
return QVariant()
elif(role!=Qt.DisplayRole):
return QVariant()
return QVariant(self.m_data[index.row()][index.column()])
if __name__ == "__main__":
app = QApplication(sys.argv);
model = Model()
proxy = QSortFilterProxyModel()
proxy.setSourceModel(model)
tv = QTableView()
tv.setModel(proxy);
tv.show();
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
proxyModel.setSourceModel(myModel)
proxyModel.setSourceModel(myModel)
To copy to clipboard, switch view to plain text mode
that
Bookmarks