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: https://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html. 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
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:
The position in the editor where the click signal was emitted. It is the absolute character position in the whole editor’s text.
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
Metamodifiermeans. If anyone knows, please share it..
self, position, modifiers): print("Hotspot clicked at position: " + str( position)) ''''''
Find out where the click was
[Under construction …]