Root cern GUI: signal from TGNumberEntry

Dear, experts

There is an example how to send signal from TGNumberEntry :

But TGNumberEntry send signal only if I press top or bottom arrows.
How to send signal when I change value using keyboard too?

Thank you in advance.


I think you misread the tutorial. If you enter a value in the text field and press enter, then you should see the value changing in the label…
Just try this version:

// Author: Ilka Antcheva   1/12/2006

// This macro gives an example of how to create a number entry
// and how to update a label according to the changed value of 
// this number entry.
// To run it do either:
// .x numberEntry.C
// .x numberEntry.C++

#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TGLayout.h>
#include <TGWindow.h>
#include <TGLabel.h>
#include <TGNumberEntry.h>
#include <TString.h>

class MyMainFrame : public TGMainFrame {

   TGCompositeFrame    *fHor1;
   TGTextButton        *fExit;
   TGGroupFrame        *fGframe;
   TGNumberEntry       *fNumber;
   TGLabel             *fLabel;

   MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
   virtual ~MyMainFrame();
   void DoSetlabel();
   ClassDef(MyMainFrame, 0)
MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h)
   : TGMainFrame(p, w, h)

   fHor1 = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
   fExit = new TGTextButton(fHor1, "&Exit", "gApplication->Terminate(0)");
   fHor1->AddFrame(fExit, new TGLayoutHints(kLHintsTop | kLHintsLeft | 
                                            kLHintsExpandX, 4, 4, 4, 4));
   AddFrame(fHor1,new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 5, 1));
   fNumber = new TGNumberEntry(this, 0, 9,999, TGNumberFormat::kNESInteger,
                                               0, 99999);
   fNumber->Connect("ValueSet(Long_t)", "MyMainFrame", this, "DoSetlabel()");
   fNumber->GetNumberEntry()->Connect("ReturnPressed()", "MyMainFrame", this,
   AddFrame(fNumber, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
   fGframe = new TGGroupFrame(this, "Value");
   fLabel = new TGLabel(fGframe, "No input.");
   fGframe->AddFrame(fLabel, new TGLayoutHints(kLHintsTop | kLHintsLeft,
                                               5, 5, 5, 5));
   AddFrame(fGframe, new TGLayoutHints(kLHintsExpandX, 2, 2, 1, 1));
   SetWindowName("Number Entry");

   // Destructor.

void MyMainFrame::DoSetlabel()
   TObject *sender = (TObject *)gTQSender;
   if (sender && sender->InheritsFrom("TGTextEntry"))
      cout << "From ReturnPressed() signal" << endl;
   else if (sender && sender->InheritsFrom("TGNumberEntry"))
      cout << "From ValueSet() signal" << endl;

   // Slot method connected to the ValueSet(Long_t) signal.
   // It displays the value set in TGNumberEntry widget.

   // Parent frame Layout() method will redraw the label showing the new value.

void numberEntry()
   new MyMainFrame(gClient->GetRoot(), 50, 50); 

Cheers, Bertrand.

1 Like

Dear Bertrand,
It was not obvious for me that I should press “enter”.

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