Caret

Your editor can display the caret (cursor) in different colors and shapes. This chapter investigates those options.

Caret foreground color

The “caret foreground color” is nothing more than the color of the caret symbol itself. You can set the color with
setCaretForegroundColor(color)
Lets set the caret color to blue:

  • QColor(…)
    self.__editor.setCaretForegroundColor(QColor(“#ff0000ff”))

     

Caret line visibility

This title – and the name of the corresponding function – might be a bit misleading. This is not about the caret itself, but the line under the caret. The function
setCaretLineVisible(visible)
determines whether the line under the caret should get a background color.

  • False
    self.__editor.setCaretLineVisible(False)

     
  • True
    self.__editor.setCaretLineVisible(True)

     

Caret line background color

A highlighted line (see previous paragraph) is yellow by default. But you can change that color easily:
setCaretLineBackgroundColor(color)

  • QColor(…)
    self.__editor.setCaretLineBackgroundColor(QColor(“#1fff0000”))

     

Caret width

Set the width of your caret in pixels. A width equal to 0 makes the caret invisible!
setCaretWidth(size)