I 'm trying to change the color of rows in a QTableView which has a QSqlQueryModel as it's model.

Here is a compilable code sample in python:
Qt Code:
  1. import sys
  2. from PyQt4 import QtGui, QtCore, QtSql
  3.  
  4. def main():
  5. app = QtGui.QApplication(sys.argv)
  6. w = MyWindow()
  7. w.show()
  8. sys.exit(app.exec_())
  9.  
  10. class MyWindow(QtGui.QTableView):
  11. def __init__(self, *args):
  12. QtGui.QTableView.__init__(self, *args)
  13.  
  14. # connect to db (if doesn't exist, it's auto-created)
  15. self.db = QtSql.QSqlDatabase.addDatabase('QSQLITE')
  16. self.db.setDatabaseName('test.db')
  17. self.db.open()
  18.  
  19. #create a table in db and add some data
  20. query = QtSql.QSqlQuery()
  21. query.exec_("DROP TABLE IF EXISTS games")
  22. query.exec_("CREATE TABLE games(id INTEGER PRIMARY KEY, hometeam TEXT, visitorteam TEXT) ")
  23. query.exec("INSERT INTO games (hometeam, visitorteam) VALUES ('Star', 'Eagles')")
  24. query.exec("INSERT INTO games (hometeam, visitorteam) VALUES ('Best team', 'Reds');")
  25.  
  26. # set the model
  27. model = QtSql.QSqlQueryModel(self)#QtGui.QStandardItemModel(0, 2)
  28. self.setModel(model)
  29. model.setQuery("SELECT * FROM games")
  30.  
  31. # paint first two rows
  32. for i in range(0, 2):
  33. model.setData(model.index(i, 0), QtGui.QBrush(QtCore.Qt.red), QtCore.Qt.BackgroundRole)
  34. model.setData(model.index(i, 1), QtGui.QBrush(QtCore.Qt.red), QtCore.Qt.BackgroundRole)
  35.  
  36.  
  37. if __name__ == "__main__":
  38. main()
To copy to clipboard, switch view to plain text mode 

What am I doing wrong?