Keyboard Event Handling in Gui

Hello,

I am working off of the tutorial gui/guitest.C, and have edited it to enabled two embedded canvas’s in the main window inside of a CompositeFrame. I have edited the file->open to open a root file and fill a combobox with the histograms that are in the root file and when one of the histograms are selected from the combobox, it is drawn in the first of the embedded canvas’s. This all works very well but I would like to be able to get keypress events when the mouse is over the histogram. I can get mouse movements and mouse clicks, and depending on how I setup the connect(), I can get key presses in the embedded canvas, but once the histogram is drawn that goes away. I want to be able to get information on the current location of the cursor and store that depending on which key is pressed and keep the mouse movement information.

If I define, not using the gui classes, a TCanvas and connect it to ProcessedEvents(), with

TCanvas c1 = new TCanvas("c1", "GAMANAL-like Fit to Gamma-Ray Peak",
          750, 700);

c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "HFitter",
          h1, "ExecuteEvent(Int_t,Int_t,Int_t,TObject*)");

Where the HFitter class controls histogram fitting and handles whether events are keypresses or mouse clicks to do various things, and h1 is a filled & drawn histogram. This works to handle BOTH keypresses and mouse clicks/movements. But not for when I have a histogram in an embedded canvas.

I have tried the following in my version of the guitest.C tutorial

    fEc1 = new TRootEmbeddedCanvas("ec1", fF5, 100, 400);
    c1 = fEc1->GetCanvas();
    c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "TestMainFrame",
          this, "ExecuteEvent(Int_t,Int_t,Int_t,TObject*)");

OR IN ANOTHER PLACE
    
    fHpx=(TH1F *)tfile->Get(T);
    fHpx->Draw();
    c1 = fEc1->GetCanvas();
    c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "TestMainFrame",
          fHpx, "ExecuteEvent(Int_t,Int_t,Int_t,TObject*)");

I have attached my code, the above two attempts can be found at lines 408 & 498 respectively. I have tried to AddInput() to the Embedded Canvas but that did not seem to help.

Any help to figure out how to enable key presses would be appreciated. I have searched the forums and found some hints but nothing that has yielded a solution.

Best,
guitest.C (28.1 KB)


_ROOT Version:6.14.06
_Platform:MacOSX Mojave 10.14.2
Compiler: Not Provided


Try to add:

   gVirtualX->SetInputFocus(fEc1->GetContainer()->GetId());

before:

   c1 = fEc1->GetCanvas();
   c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "TestMainFrame",
         this, "ExecuteEvent(Int_t,Int_t,Int_t,TObject*)");

Cheers, Bertrand.

Bertrand,

Thank you for your reply. I initially wrote a reply that your suggestion did not work but I attempted to issue the command before the second second set of code above before I finished my reply,

    fHpx=(TH1F *)tfile->Get(T);
    fHpx->Draw();
    c1 = fEc1->GetCanvas();
    c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "TestMainFrame",
          fHpx, "ExecuteEvent(Int_t,Int_t,Int_t,TObject*)");

rather than where you suggested and now I have all of the functionality that I needed! Thank you very much.

If I may trouble you with another question, when the program runs the mainframe window that opens has all of the widgets inside misplaced and mostly non-visible, but once you adjust the window size by grabbing a corner for instance, everything snaps into place and it looks nice. Is there a way to fix this? Not the end of the world but does look rather unprofessional at the start.

best,

Matthew

Add fMain->Layout();, e.g. after fMain->MapSubwindows();

   fMain->MapSubwindows();
   fMain->Layout();

Cheers, Bertrand.

This is unrelated, please open an new topic

Cheers, Bertrand.

Done, I have deleted and reposted my question under a new topic.

Thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.