Logo ROOT  
Reference Guide
buttongroupState.C File Reference

Detailed Description

A simple example that shows the enabled and disabled state of a button group with radio and check buttons.

#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TGLayout.h>
#include <TGWindow.h>
#include <TGLabel.h>
#include <TString.h>
#include <TGButtonGroup.h>
class IDList {
private:
Int_t nID; // creates unique widget's IDs
public:
IDList() : nID(0) {}
~IDList() {}
Int_t GetUnID(void) { return ++nID; }
};
class MyButtonTest : public TGMainFrame {
private:
TGTextButton *fExit; // Exit text button
TGVButtonGroup *fButtonGroup; // Button group
TGCheckButton *fCheckb[4]; // Check buttons
TGRadioButton *fRadiob[2]; // Radio buttons
IDList IDs; // Widget IDs generator
public:
MyButtonTest(const TGWindow *p, UInt_t w, UInt_t h);
virtual ~MyButtonTest();
void DoExit(void);
void SetGroupEnabled(Bool_t);
ClassDef(MyButtonTest, 0)
};
MyButtonTest::MyButtonTest(const TGWindow *p, UInt_t w, UInt_t h)
: TGMainFrame(p, w, h)
{
SetCleanup(kDeepCleanup);
Connect("CloseWindow()", "MyButtonTest", this, "DoExit()");
DontCallClose();
TGHorizontalFrame *fHL2 = new TGHorizontalFrame(this, 70, 100);
fCheckb[0] = new TGCheckButton(fHL2, new TGHotString("Enable BG"),
IDs.GetUnID());
fCheckb[0]->SetToolTipText("Enable/Disable the button group");
1, 1, 1, 1));
fButtonGroup = new TGVButtonGroup(fHL2, "My Button Group");
fCheckb[1] = new TGCheckButton(fButtonGroup, new TGHotString("CB 2"),
IDs.GetUnID());
fCheckb[2] = new TGCheckButton(fButtonGroup, new TGHotString("CB 3"),
IDs.GetUnID());
fCheckb[3] = new TGCheckButton(fButtonGroup, new TGHotString("CB 4"),
IDs.GetUnID());
fRadiob[0] = new TGRadioButton(fButtonGroup, new TGHotString("RB 1"),
IDs.GetUnID());
fRadiob[1] = new TGRadioButton(fButtonGroup, new TGHotString("RB 2"),
IDs.GetUnID());
fButtonGroup->Show();
1, 1, 1, 1));
AddFrame(fHL2);
fCheckb[0]->Connect("Toggled(Bool_t)", "MyButtonTest", this,
"SetGroupEnabled(Bool_t)");
TGHorizontalFrame *fHL3 = new TGHorizontalFrame(this, 70, 100, kFixedWidth);
fExit = new TGTextButton(fHL3, "&Exit", IDs.GetUnID());
fExit->Connect("Clicked()", "MyButtonTest", this, "DoExit()");
AddFrame(fHL3, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,1,1,1,1));
//Default state
fCheckb[0]->SetOn();
fButtonGroup->SetState(kTRUE);
SetWindowName("My Button Group");
MapSubwindows();
Resize(GetDefaultSize());
MapWindow();
fButtonGroup->SetRadioButtonExclusive(kTRUE);
fRadiob[1]->SetOn();
};
MyButtonTest::~MyButtonTest()
{
// Destructor.
Cleanup();
}
void MyButtonTest::DoExit()
{
// Exit this application via the Exit button or Window Manager.
// Use one of the both lines according to your needs.
// Please note to re-run this macro in the same ROOT session,
// you have to compile it to get signals/slots 'on place'.
//DeleteWindow(); // to stay in the ROOT session
gApplication->Terminate(); // to exit and close the ROOT session
}
void MyButtonTest::SetGroupEnabled(Bool_t on)
{
fButtonGroup->SetState(on);
}
void buttongroupState()
{
new MyButtonTest(gClient->GetRoot(),100,100);
}
Author
Roel Aaij 4/07/2007

Definition in file buttongroupState.C.

TGWindow
Definition: TGWindow.h:31
kLHintsCenterX
@ kLHintsCenterX
Definition: TGLayout.h:38
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
kFixedWidth
@ kFixedWidth
Definition: GuiTypes.h:387
TGMainFrame
Definition: TGFrame.h:444
TGLayout.h
TGHotString
Definition: TGString.h:52
TGTextButton
Definition: TGButton.h:142
Int_t
int Int_t
Definition: RtypesCore.h:45
TGHorizontalFrame
Definition: TGFrame.h:423
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TString.h
TGWindow.h
gClient
#define gClient
Definition: TGClient.h:166
TApplication.h
TGCheckButton
Definition: TGButton.h:264
TGVButtonGroup
Definition: TGButtonGroup.h:104
kLHintsCenterY
@ kLHintsCenterY
Definition: TGLayout.h:41
TGRadioButton
Definition: TGButton.h:322
h
#define h(i)
Definition: RSha256.hxx:124
TGFrame.h
TGLayoutHints
Definition: TGLayout.h:57
gApplication
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
TGButtonGroup.h
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TApplication::Terminate
virtual void Terminate(Int_t status=0)
TGClient.h
TGLabel.h
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGButton.h
kDeepCleanup
@ kDeepCleanup
Definition: TGFrame.h:51
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:43
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1102