Hotspot signals

Catch the mouseclick!

Hotspots react on mouseclicks! Duh.. that’s what they exist for.
Hopefully you know how the signal-slot mechanism works in PyQt5. If not, please read the documentation on this link: On this page, we will apply the signal-slot mechanism on a mouseclick event on hotspots.

Step 1: Connect the signal to the slot

Your editor fires the signal  SCN_HOTSPOTCLICK  anytime the user clicks on a hotspot. It doesn’t matter which hotspot he clicked on. The signal is sort of ‘global’ for the editor as a whole.
You need to connect this signal to a slot. A slot is just a Python function which you want to get called everytime the signal fires. This is how you do it:


Step 2: Implement the function (the slot)

The slot should have two parameters:
some_function(self, position, modifiers)

  • position
    The position in the editor where the click signal was emitted. It is the absolute character position in the whole editor’s text.
  • modifiers
    This parameter indicates if anything special happened while the user clicked the mouse. Did he press the Ctrl key while clicking? Or perhaps the Alt key? The possible values for the parameter are:

    • Qt.ControlModifier
    • Qt.ShiftModifier
    • Qt.AltModifier
    • Qt.MetaModifier

    I think the first three keys are pretty clear. But I have to admit that I’ve no idea what Metamodifier  means. If anyone knows, please share it..

    def some_function(self, position, modifiers):
        print("Hotspot clicked at position: " + str(position))


Find out where the click was

[Under construction …]