Try to place the cursor in ``line`` at ``col`` if possible,
        otherwise place it at the end.

def placeCursor(self, line, col):
        """
        Try to place the cursor in ``line`` at ``col`` if possible,
        otherwise place it at the end.
        """
        num_lines, num_col = self.qteWidget.getNumLinesAndColumns()

        # Place the cursor at the specified position if possible.
        if line >= num_lines:
            line, col = num_lines, num_col
        else:
            text = self.qteWidget.text(line)
            if col >= len(text):
                col = len(text) - 1

        self.qteWidget.setCursorPosition(line, col)