Change the character format of one or more characters.

        If ``charFormat`` is **None** then only the color and font
        weight of the characters are changed to ``colorCode`` and
        ``fontWeight``, respectively.

        |Args|

        * ``widgetObj`` (**QWidget**): the ``QTextEdit`` holding
          the characters.
        * ``setPos`` (**tuple** of **int**): character positions
          inside the widget.
        * ``colorCode`` (**QColor**): eg. ``QtCore.Qt.blue``
        * ``fontWeight`` (**int**): font weight.
        * ``charFormat`` (**QTextCharFormat**): the character
          format to apply (see Qt documentation for details.)

        |Returns|

        * **list**: the original character format of the replaced
          characters. This list has the same length as ``setPos``.

        |Raises|

        * **None**

def highlightCharacters(self, widgetObj, setPos, colorCode,
                            fontWeight, charFormat=None):
        """
        Change the character format of one or more characters.

        If ``charFormat`` is **None** then only the color and font
        weight of the characters are changed to ``colorCode`` and
        ``fontWeight``, respectively.

        |Args|

        * ``widgetObj`` (**QWidget**): the ``QTextEdit`` holding
          the characters.
        * ``setPos`` (**tuple** of **int**): character positions
          inside the widget.
        * ``colorCode`` (**QColor**): eg. ``QtCore.Qt.blue``
        * ``fontWeight`` (**int**): font weight.
        * ``charFormat`` (**QTextCharFormat**): the character
          format to apply (see Qt documentation for details.)

        |Returns|

        * **list**: the original character format of the replaced
          characters. This list has the same length as ``setPos``.

        |Raises|

        * **None**
        """

        # Get the text cursor and character format.
        textCursor = widgetObj.textCursor()
        oldPos = textCursor.position()
        retVal = []

        # Change the character formats of all the characters placed at
        # the positions ``setPos``.
        for ii, pos in enumerate(setPos):
            # Extract the position of the character to modify.
            pos = setPos[ii]

            # Ignore invalid positions. This can happen if the second
            # character does not exist and the find-functions in the
            # ``cursorPositionChangedEvent`` method returned
            # '-1'. Also, store **None** as the format for this
            # non-existent character.
            if pos < 0:
                retVal.append(None)
                continue

            # Move the text cursor to the specified character position
            # and store its original character format (necessary to
            # "undo" the highlighting once the cursor was moved away
            # again).
            textCursor.setPosition(pos)
            retVal.append(textCursor.charFormat())

            # Change the character format. Either use the supplied
            # one, or use a generic one.
            if charFormat:
                # Use a specific character format (usually used to
                # undo the changes a previous call to
                # 'highlightCharacters' has made).
                fmt = charFormat[ii]
            else:
                # Modify the color and weight of the current character format.
                fmt = textCursor.charFormat()

                # Get the brush and specify its foreground color and
                # style. In order to see the characters it is
                # necessary to explicitly specify a solidPattern style
                # but I have no idea why.
                myBrush = fmt.foreground()
                myBrush.setColor(colorCode)
                myBrush.setStyle(QtCore.Qt.SolidPattern)
                fmt.setForeground(myBrush)
                fmt.setFontWeight(fontWeight)

            # Select the character and apply the selected format.
            textCursor.movePosition(QtGui.QTextCursor.NextCharacter,
                                    QtGui.QTextCursor.KeepAnchor)
            textCursor.setCharFormat(fmt)

        # Apply the textcursor to the current element.
        textCursor.setPosition(oldPos)
        widgetObj.setTextCursor(textCursor)
        return retVal