Hotspots

A hotspot is a clickable piece of text in your editor.

Setting a hotspot

The most convenient way to set hotspots it to define a style as “hotspot-style”. In other words, being a hotspot is an attribute of the QsciStyle object.
To set – for example – style 1 as a hotspot style, add the following code in your lexer:

editor = self.parent()
editor.SendScintilla(editor.SCI_STYLESETHOTSPOT, 1, True)

Marking a style as a hotspot style is something you better do after you’ve configured the style. So in the example from the previous chapter, we’d do that at the end of the __init__() function in the lexer class:

class MyLexer(QsciLexerCustom):

    def __init__(self, parent):
        super(MyLexer, self).__init__(parent)

        # Default text settings
        # ----------------------
        self.setDefaultColor(QColor("#ff000000"))
        self.setDefaultPaper(QColor("#ffffffff"))
        self.setDefaultFont(QFont("Consolas", 14))

        # Initialize colors per style
        # ----------------------------
        self.setColor(QColor("#ff000000"), 0)   # Style 0: black
        self.setColor(QColor("#ff7f0000"), 1)   # Style 1: red
        self.setColor(QColor("#ff0000bf"), 2)   # Style 2: blue
        self.setColor(QColor("#ff007f00"), 3)   # Style 3: green

        # Initialize paper colors per style
        # ----------------------------------
        self.setPaper(QColor("#ffffffff"), 0)   # Style 0: white
        self.setPaper(QColor("#ffffffff"), 1)   # Style 1: white
        self.setPaper(QColor("#ffffffff"), 2)   # Style 2: white
        self.setPaper(QColor("#ffffffff"), 3)   # Style 3: white

        # Initialize fonts per style
        # ---------------------------
        self.setFont(QFont("Consolas", 14, weight=QFont.Bold), 0)   # Style 0: Consolas 14pt
        self.setFont(QFont("Consolas", 14, weight=QFont.Bold), 1)   # Style 1: Consolas 14pt
        self.setFont(QFont("Consolas", 14, weight=QFont.Bold), 2)   # Style 2: Consolas 14pt
        self.setFont(QFont("Consolas", 14, weight=QFont.Bold), 3)   # Style 3: Consolas 14pt

        # Define style 1 to be hotspot
        # -----------------------------
        editor = self.parent()
        editor.SendScintilla(editor.SCI_STYLESETHOTSPOT, 1, True)
    ''''''

    def language(self):
        [...]
    ''''''

    def description(self, style_nr):
        [...]
    ''''''

    def styleText(self, start, end):
        # Called everytime the editors text has changed
        [...]
    ''''''
	
'''--- end class ---'''

Now any token that has been highlighted in style 1 is a hotspot!

 

Hotspot look and feel

You can define several properties that impact the way your hotspots look. Please note that these settings apply to all  hotspots in the editor.

Active foreground color
This setting changes the active (when the mouse is over the hotspot) foreground color of all  hotspots.

editor.setHotspotForegroundColor(QColor(“#ffcf4444”))

 
Active background color
This setting changes the active (when the mouse is over the hotspot) background color of all  hotspots.

editor.setHotspotBackgroundColor(QColor(“#ffaaaaaa”))

Unfortunately, this function doesn’t work properly in the current QScintilla version. Therefore you need to use the SendScintilla functionality:

editor.SendScintilla(editor.SCI_SETHOTSPOTACTIVEBACK, True, 0xaaaaaa)

 
Active underlining
This setting selects the visibility of underlining on an active (when the mouse is over the hotspot) hotspot. By default this setting is on.

editor.setHotspotUnderline(True)