Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
numberEntry.C File Reference

Detailed Description

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:

#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 {
private:
TGTextButton *fExit;
TGGroupFrame *fGframe;
TGNumberEntry *fNumber;
TGLabel *fLabel;
public:
MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
~MyMainFrame() override;
void DoSetlabel();
ClassDefOverride(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->Connect("ValueSet(Long_t)", "MyMainFrame", this, "DoSetlabel()");
(fNumber->GetNumberEntry())->Connect("ReturnPressed()", "MyMainFrame", this, "DoSetlabel()");
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));
SetCleanup(kDeepCleanup);
SetWindowName("Number Entry");
Resize(GetDefaultSize());
MapWindow();
}
MyMainFrame::~MyMainFrame()
{
// Destructor.
Cleanup();
}
void MyMainFrame::DoSetlabel()
{
// Slot method connected to the ValueSet(Long_t) signal.
// It displays the value set in TGNumberEntry widget.
fLabel->SetText(Form("%ld", fNumber->GetNumberEntry()->GetIntNumber()));
// Parent frame Layout() method will redraw the label showing the new value.
fGframe->Layout();
}
{
new MyMainFrame(gClient->GetRoot(), 50, 50);
}
@ kFixedWidth
Definition GuiTypes.h:387
#define h(i)
Definition RSha256.hxx:106
unsigned int UInt_t
Definition RtypesCore.h:46
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
#define gClient
Definition TGClient.h:157
@ kDeepCleanup
Definition TGFrame.h:42
@ kLHintsRight
Definition TGLayout.h:26
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsBottom
Definition TGLayout.h:29
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:287
A composite frame with a border and a title.
Definition TGFrame.h:522
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:385
This class handles GUI labels.
Definition TGLabel.h:24
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:397
TGNumberEntry is a number entry input widget with up/down buttons.
@ kNEANonNegative
Non-negative number.
@ kNESInteger
Style of number entry field.
@ kNELLimitMinMax
Both lower and upper limits.
Yield an action as soon as it is clicked.
Definition TGButton.h:142
ROOT GUI Window base class.
Definition TGWindow.h:23
Author
Ilka Antcheva 1/12/2006

Definition in file numberEntry.C.