code: def get_pos_in_delegate(self, index, globalpos):
          
          rect = self.visualRect(index)  # rect of the index
          p = self.viewport().mapToGlobal(rect.topLeft())
          return globalpos - p
docs: Map the global position to the position relative to the
          given index
  
          :param index: the index to map to
          :type index: :class:`QtCore.QModelIndex`
          :param globalpos: the global position
          :type globalpos: :class:`QtCore.QPoint`
          :returns: The position relative to the given index
          :rtype: :class:`QtCore.QPoint`
          :raises: None