Skip to content

Colours

ScintillaEdit's colour methods (styleSetFore(), setElementColour(), ...) take and return QColor. Scintilla's own messages use packed integers instead: 0xBBGGRR (red in the low byte), or 0xAABBGGRR for the ...Translucent/ element/representation colours that carry alpha -- the opposite byte order from Qt's 0xAARRGGBB. These two functions convert between the two, for code using the raw send().

from pyside6_scintilla import Scintilla, colour_to_scintilla

editor.send(Scintilla.Message.StyleSetFore, style, colour_to_scintilla("#00ff00"))

colour_to_scintilla(colour, alpha=False)

Pack a colour into Scintilla's integer format, for the raw send().

Scintilla's colour messages take 0xBBGGRR (red in the low byte), and its colouralpha ones 0xAABBGGRR (pass alpha=True) -- the opposite byte order from Qt's 0xAARRGGBB. ScintillaEdit's typed colour methods take a QColor and convert for you; this is for the raw message layer.

colour is a QColor, a Qt.GlobalColor, or a colour name such as "#00ff00" or "red". An int is rejected rather than guessed at, since it could be in either byte order. (The typed methods, going through PySide6's own QColor conversion, can't check this: there an invalid colour name silently becomes black, and an int is read as Qt's 0xRRGGBB.)

Raises TypeError for an int, and ValueError for an invalid colour (e.g. an unknown name).

colour_from_scintilla(value, alpha=False)

Unpack a colour from Scintilla's integer format, e.g. a raw send() result.

value is 0xBBGGRR, or 0xAABBGGRR with alpha=True; without alpha the result is opaque. The inverse of colour_to_scintilla().