Mouse clicks

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: 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:
setMarginSensitivity(margin_nr, sensitivity)


Step 2: Connect the signal to the slot

Next you need to connect the signal  marginClicked  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:

Please note that the name of the signal is not  margin_0_Clicked , or  margin_1_Clicked , but just the general name  marginClicked . This is the signal that gets fired no matter on what margin the user clicks. Luckily, some parameters are passed on to the slot some_function such that you know where he clicked. See next step..


Step 3: Implement the function (the slot)

The slot should have 3 parameters:
some_function(self, margin_nr, line_nr, state)

  • margin_nr
    The nr of the margin that has been clicked (start counting from 0).
  • line_nr
    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.
  • state
    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..