Hi there people. I'm pretty new at PyQt, or Qt at all,and was trying for some time to write few things with variable success. This time I feel really stuck, so I decide to ask for the kind help of someone, who actually knows what to do

So here is my case:

I have a QT App (PyQt actually), which reads some data from a server based sql database, and updates a QStandardItemModel which is used by a QTreeView. I may be wrong, but I guessed the StandardModel is a better choise for my needs, because it also reads the messages from some server node across our network and so on. So my actual question is how can I refresh the QStandartItemModel, but retain the selected row also. I've made a QThread which emits a "refresh" signal every 5 second, and connected it to a custom pyqtSlot in my StandartItemModel which actually calls the __init__ procedure of the model and then reattaches the model to the QTreeView:
Qt Code:
  1. class fileList(QtGui.QStandardItemModel):
  2. def __init__(self, parent, viewer, thread = None):
  3. QtGui.QStandardItemModel.__init__(self,parent)
  4. self.viewer = viewer
  5. """
  6. Code...Code...Code
  7. """
  8. if self.viewer:
  9. self.viewer.setAlternatingRowColors(True)
  10. self.viewer.setSortingEnabled(True)
  11. self.viewer.setIndentation(0)
  12. self.viewer.setSelectionMode(QtGui.QAbstractItemView.MultiSelection)
  13.  
  14. # This connects the QThread signal to the model's slot
  15. if thread:
  16. global refreshThread
  17. self.connect(refreshThread, QtCore.SIGNAL("refresh()"), self.viewer, QtCore.SLOT('reset()'))
  18.  
  19. @QtCore.pyqtSlot()
  20. def rebuild(self, thread = 0):
  21. state = QtGui.QAbstractItemView.state(self.viewer)
  22. if state:
  23. return # Halt if editing
  24. self.__init__(None, self.viewer, 0)
  25. self.viewer.setModel(self)
To copy to clipboard, switch view to plain text mode 
and the QThread Class:
Qt Code:
  1. class Reloader(QtCore.QThread):
  2. def __init__(self, parent = None):
  3. QtCore.QThread.__init__(self, parent)
  4.  
  5. def run(self):
  6. while True:
  7. self.timeout = REFRESH if REFRESH != 0 else 0.1
  8. if self.timeout == -1:
  9. print "Refresh Halted"
  10. break
  11. self.emit(QtCore.SIGNAL('refresh()'))
  12. time.sleep(self.timeout)
To copy to clipboard, switch view to plain text mode 
So what is the right way to refresh the QStandardItemModel and retain the selection? I've tried using a QSelectionModel to which I added the selection and the set it as a selection model for the model viewer, but it messes up with my active selection until it refreshes, so I suspect it's totally wrong