Are there callbacks/signalhandlers... for TCanvas/TPad?

Hi, just a question: is it possible to register callbacks/signalhandlers/whatever for eg. clicking on a TCanvas (or maybe TPad)? I found AddExec, which is roughly what I need, but I don’t know how to decide if it’s a move or click, and i also need the coordinates of the click. is it possible?
Greetings, Christian

Hi Christian,

There are several options. By using AddExec, take a look at $ROOTSYS/tutorials/hist/DynamicSlice.C, exec1.C and exec2.C.
You can also use signal/slots and connect to ProcessedEvent(). For this, take a look at $ROOTSYS/tutorials/gui/exec3.C

Cheers, Bertrand.

Hi, and thank you for your answer.
the Connect method is just what i need. But I’m not quite sure about the event numbers. is there an overview anywhere? it seems, that 1 is MouseDown and 11 MouseUp, and that 5x is moving the mouse, but what are the differences there?

Those event numbers are defined in Buttons.h:

enum EEventType { kNoEvent = 0, kButton1Down = 1, kButton2Down = 2, kButton3Down = 3, kKeyDown = 4, kWheelUp = 5, kWheelDown = 6, kButton1Shift = 7, kButton1ShiftMotion = 8, kButton1Up = 11, kButton2Up = 12, kButton3Up = 13, kKeyUp = 14, kButton1Motion = 21, kButton2Motion = 22, kButton3Motion = 23, kKeyPress = 24, kButton1Locate = 41, kButton2Locate = 42, kButton3Locate = 43, kESC = 27, kMouseMotion = 51, kMouseEnter = 52, kMouseLeave = 53, kButton1Double = 61, kButton2Double = 62, kButton3Double = 63 };
Cheers, Bertrand.

Than you, Bertrand. Just what I needed.
I still have one Problem: I have a TCanvas with 4 TPads and in each of these 4 Pads, a custom class is drawn. When I click on this class, the Sender is this class, but i need the Pad it is in. The class doesn’t know anything about the pad it is drawn in, unfortunately. So can I get somehow (maybe xy-coordinates) the pad, i’m currently clicking?

Hi Christian,

You can connect to the “TCanvas::Selected(TVirtualPad*, TObject*, Int_t)” signal, you will then have the information about the event, the selected object and the pad.
(see the list of available signals in TCanvas.h)

Cheers, Bertrand.

No, i still need the coordinates anyway. I can get the pad by comparing the name of my own object with the names of the pads in the canvas. not very nice, but for now its ok.

Thaanks again

But you can connect to several (both) signals…
And you’re welcome!
Cheers, Bertrand.

Yeah, I know that I can connect several signals. I’m quite new to root, so maybe I’m missing something, but if I connect to different signals, the signals are emitted at different times. And I also need different functions, because of differing prototypes. But I need the information of click position and TPad this position coresponds to simultaneously.
I already had the idea to connect to the TPads signals, but TPads do not have “ProcessedEvent” as signal.
I’m also not sure, when exactly selected is emitted (is there a description of the signals anywhere?). If is clicked? (if i click something, it is selected, if i click again, will it be selected again, or no signal, becaus it is already selected?)

You can look in the source code (TCanvas.cxx) where and when signals are emitted. Selected is emitted each time, and Picked is emitted if the selected object is different than the previous one.
Note that you can simply get the Pad with at coordinates x,y, by calling TCanvas::Pick(Int_t px, Int_t py, TObject* prevSelObj), like this:

TPad *pad = fCanvas->Pick(x, y, 0);This should solve your problem. :wink:

Cheers, Bertrand.

yeah thanks, exactly, what I was looking for.
Sometimes it’s a bit hard to find a specific memberfunction in the very long list, the classes have…