code: def updateGeometry(self):
          
          WIDGET_BORDER_MARGIN = 5
          SCROLLBAR_WIDTH = 30  # just a guess
  
          sizeHint = self.sizeHint()
          width = sizeHint.width()
          height = sizeHint.height()
  
          cursorRect = self._qpart.cursorRect()
          parentSize = self.parentWidget().size()
  
          spaceBelow = parentSize.height() - cursorRect.bottom() - WIDGET_BORDER_MARGIN
          spaceAbove = cursorRect.top() - WIDGET_BORDER_MARGIN
  
          if height <= spaceBelow or \
             spaceBelow > spaceAbove:
              yPos = cursorRect.bottom()
              if height > spaceBelow and \
                 spaceBelow > self.minimumHeight():
                  height = spaceBelow
                  width = width + SCROLLBAR_WIDTH
          else:
              if height > spaceAbove and \
                 spaceAbove > self.minimumHeight():
                  height = spaceAbove
                  width = width + SCROLLBAR_WIDTH
              yPos = max(3, cursorRect.top() - height)
  
          xPos = cursorRect.right() - self._horizontalShift()
  
          if xPos + width + WIDGET_BORDER_MARGIN > parentSize.width():
              xPos = max(3, parentSize.width() - WIDGET_BORDER_MARGIN - width)
  
          self.setGeometry(xPos, yPos, width, height)
          self._closeIfNotUpdatedTimer.stop()
docs: Move widget to point under cursor