Margins can react on mouseclicks!
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 in the margin.
Step 1: Make your margin sensitive
First you should ask your editor to make a specific margin sensitive. You need the following function for that:
Step 2: Connect the signal to the slot
Next you need to connect the signal
Please note that the name of the signal is not
Step 3: Implement the function (the slot)
The slot should have 3 parameters:
The nr of the margin that has been clicked (start counting from 0).
The nr of the line that has been clicked (start counting from 0). Attention, the line numbers displayed in the line number margin start counting from one. This might cause some confusion if you don’t pay attention.
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..