SetBit(kNotEditable) in TRootEmbedded Canvas

I have a stand alone program running on linux. I have a very curious problem.

My main window is created using a TGMainFrame. Inside this frame I
add a bunch of other stuff, menus, status bar etc. I also add a TRootEmbeddedCanvas object. I then draw a variety of TGraphs on this canvas. The outline box for the TGraph can be moved with the mouse. I’d like to prevent this. I tried using GetCanvas()->SetBit(kNotEditable) on
the embedded canvas, however, when I draw on it, it now creates
a brand new canvas. Definitely not desirable.

The main question is, how do I prevent the axis box from being moved
by the mouse.

Secondary to that is, why does setting kNotEditable cause the embedded
canvas to spawn a new frame.

As Always, Warm Regards.

Hi Chris,

You can use the method TPad::SetEditable(Bool_t mode) that sets the pad/canvas editable or not according to the ‘mode’ parameter.
If the pad is not editable:

  • you cannot modify the pad and its objects via the mouse.
  • you cannot add new objects to the pad
    To add an object in the canvas you need to set it back as editable; otherwise a new canvas is created and the object is drawn there.

Cheers, Ilka

Hi Ilka,
Thanks for the reply. I’m still having problems. I did use your suggestion of setting no editable. An interesting artifact, which I think is good, is that if the embedded canvas is set as not editable and a
TGraph::Draw is made, it is coded in to open up a new canvas.

So, what I had to do was put SetEditable(kTRUE); Draw(); SetEditable(kFALSE); This does keep the box around the axis frame from moving.

What I am ultimately trying to do is create a rubberband zoom box in
my plot.

In my quest to do this I’ve put in a handler to capture mouse events
but it doesn’t appear to work. I’ve attached the code if you have the fortitude to look through it. To capture the events, I made a class (SVPDrawArea) that inherits from TGCompositeFrame and added virtual functions to route MotionEvent etc through this class.

This class is embedded in a dialog (TGTransientFrame) and then
adds a TRootEmbeddedCanvas to itself where ultimately I draw using TGraph.

Having said all that, it is frustrating that I can’t get the HandleEvent in SVPDrawArea to get called.

Any help you can provide would be very nice.
Thank you!
SVPEdit.cpp (47.5 KB)
SVPEdit.cpp (47.5 KB)

Sorry about that.

Can’t seem to get the header file posted. I use the extension hh so
where you see include SVPEdit.hh it is this file.
SVPEdit.h (8.77 KB)

To create a rubberband within TCanvas (it doesn’t matter whether it is embedded or not) no “handler” is needed. What you have to do is to create your own TObject and add this TObject to the current TPad (in other words you should call its methid Draw)

Check, for example the class

That is designed to create the rubberband around of 3D objects. You may neglect it is for 3D objects and use the technique this class demonstrates to create the rubberband. (just copy past its code with the mouse )

You should create a class and provide the implementations for 2 methods:

[code]class TBubberBand : public TObject {
. . .
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
. . .


The first method (see: … oPrimitive
) should return ZERO as soon as you want to draw the rubberband.

This forces ROOT TCanvas to select very this object and call the selected object (i.e. your TRubbernBand object) ExecuteEvent method for each mouse movement.

Now you you have to provide the code with your vesion of ExecuteEvent to respond to the mouse event properly

You may realize the method … ecuteEvent
does draw the kind of rubberband and keep track of the mouse coordinates to return it as soon as you release the mouse button.

Sorry forget to mention. Tthe class described above will resolve your original issue as well.

. . .

The outline box for the TGraph can be moved with the mouse. I’d like to prevent this.
. . .

how do I prevent the axis box from being moved . . .
by the mouse.
. . .


This did work quite nicely. It is always somewhat of a task to find example code. I am always sure that it is somewhere. I am slowly getting better at finding it.
Chris :stuck_out_tongue: