title: QStyledItemDelegate paint refresh issues
body: <p>I am currently trying to wrap my head around the model-view approach and write a thumbnail viewer application.</p>
  
  <p>In this example I simply try to draw 20 boxes, but I get what seems like a random selection which updates on mouse movement. Scrolling makes things even worse and draws sometimes only have the boxes etc. Also the text seems to be not rendered at all.</p>
  
  <p>To me it looks like a refresh/update problem of the paint method.
  Am I missing something here?</p>
  
  <p><a href="https://i.stack.imgur.com/uJlJv.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uJlJv.jpg" alt="paint problem"></a></p>
  
  <p>Ultimately I need to display a lot of items. All containing a few labels and a pixmap which needs to be updated at runtime. So I thought painting them would be the fastest solution. Alternatively I tried rendering my widgets in the paint method with:</p>
  
  <pre><code>customWidget.render(painter, QtCore.QPoint(0,0), renderFlags=QtGui.QWidget.DrawChildren)
  </code></pre>
  
  <p>which seems to be slower, but at least working.</p>
  
  <p>Here is a minimal working example to illustrate my problem:</p>
  
  <pre><code>import sys
  from PySide import QtCore
  from PySide import QtGui
  
  elements = range(20)
  
  class ElementListModel(QtCore.QAbstractListModel):
      def __init__(self, elements = [], parent = None):
          super(ElementListModel, self).__init__()
          self.__elements = elements
  
      def rowCount(self, parent):
          return len(self.__elements)
  
      def data(self, index, role):
          if role == QtCore.Qt.DisplayRole:
              return str(self.__elements[index.row()])
  
  class ElementThumbDelegate(QtGui.QStyledItemDelegate):
      def __init__(self, view, parent=None):
          super(ElementThumbDelegate, self).__init__(parent)
  
      def paint(self, painter, options, index):
  
          width = options.rect.width()
          height = options.rect.height()
  
          painter.setRenderHint(QtGui.QPainter.Antialiasing)
          painter.setPen(QtGui.QColor(255, 255, 255))
          painter.setBrush(QtGui.QColor(10, 10, 10))
          painter.drawRect(0, 0, width, height)
          painter.drawText(options.rect, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter, str(index.data()))
          painter.translate(options.rect.topLeft())
  
      def sizeHint(self, options, index):
          return QtCore.QSize(50, 50)
  
  def main():
      app = QtGui.QApplication(sys.argv)
      viewer = QtGui.QListView()
  
      viewModel = ElementListModel(elements)
      viewer.setModel(viewModel)
      viewer.setViewMode(QtGui.QListView.IconMode)
      viewer.setItemDelegate(ElementThumbDelegate(viewer))
  
      viewer.show()
      sys.exit(app.exec_())
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>Thanks in advance. Any help or pointers where to look next would be highly appreciated!</p>