Why are you using QItemSelectionModel here? You can substitute first 15 lines of your code with one line that uses the method I gave you in my previous post.