code: def scroll_to_item(self, index):
          
          spacing_between_items = self.scene.verticalSpacing()
          height_view = self.scrollarea.viewport().height()
          height_item = self.scene.itemAt(index).sizeHint().height()
          height_view_excluding_item = max(0, height_view - height_item)
  
          height_of_top_items = spacing_between_items
          for i in range(index):
              item = self.scene.itemAt(i)
              height_of_top_items += item.sizeHint().height()
              height_of_top_items += spacing_between_items
  
          pos_scroll = height_of_top_items - height_view_excluding_item // 2
  
          vsb = self.scrollarea.verticalScrollBar()
          vsb.setValue(pos_scroll)
docs: Scroll to the selected item of ThumbnailScrollBar.