ROOT
Version v6.32
master
v6.34
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
►
ROOT
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
buttongroupState.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_gui
3
/// A simple example that shows the enabled and disabled state of a button group with radio and check buttons.
4
///
5
/// \macro_code
6
///
7
/// \author Roel Aaij 4/07/2007
8
9
#include <
TApplication.h
>
10
#include <
TGClient.h
>
11
#include <
TGButton.h
>
12
#include <
TGFrame.h
>
13
#include <
TGLayout.h
>
14
#include <
TGWindow.h
>
15
#include <
TGLabel.h
>
16
#include <
TString.h
>
17
#include <
TGButtonGroup.h
>
18
19
class
IDList
{
20
21
private
:
22
Int_t
nID
;
// creates unique widget's IDs
23
24
public
:
25
IDList
() :
nID
(0) {}
26
~IDList
() {}
27
Int_t
GetUnID
(
void
) {
return
++
nID
; }
28
};
29
30
class
MyButtonTest
:
public
TGMainFrame
{
31
32
private
:
33
TGTextButton
*
fExit
;
// Exit text button
34
TGVButtonGroup
*
fButtonGroup
;
// Button group
35
TGCheckButton
*
fCheckb
[4];
// Check buttons
36
TGRadioButton
*
fRadiob
[2];
// Radio buttons
37
IDList
IDs
;
// Widget IDs generator
38
39
public
:
40
MyButtonTest
(
const
TGWindow
*
p
,
UInt_t
w
,
UInt_t
h
);
41
~MyButtonTest
()
override
;
42
43
void
DoExit(
void
);
44
void
SetGroupEnabled
(
Bool_t
);
45
46
ClassDef
(
MyButtonTest
, 0)
47
};
48
49
MyButtonTest::MyButtonTest(
const
TGWindow
*
p
,
UInt_t
w
,
UInt_t
h
)
50
:
TGMainFrame
(
p
,
w
,
h
)
51
{
52
SetCleanup(
kDeepCleanup
);
53
54
Connect(
"CloseWindow()"
,
"MyButtonTest"
,
this
,
"DoExit()"
);
55
DontCallClose();
56
57
TGHorizontalFrame
*
fHL2
=
new
TGHorizontalFrame
(
this
, 70, 100);
58
fCheckb
[0] =
new
TGCheckButton
(
fHL2
,
new
TGHotString
(
"Enable BG"
),
59
IDs
.GetUnID());
60
fCheckb
[0]->SetToolTipText(
"Enable/Disable the button group"
);
61
fHL2
->AddFrame(
fCheckb
[0],
new
TGLayoutHints
(
kLHintsCenterX
|
kLHintsCenterY
,
62
1, 1, 1, 1));
63
fButtonGroup
=
new
TGVButtonGroup
(
fHL2
,
"My Button Group"
);
64
fCheckb
[1] =
new
TGCheckButton
(
fButtonGroup
,
new
TGHotString
(
"CB 2"
),
65
IDs
.GetUnID());
66
fCheckb
[2] =
new
TGCheckButton
(
fButtonGroup
,
new
TGHotString
(
"CB 3"
),
67
IDs
.GetUnID());
68
fCheckb
[3] =
new
TGCheckButton
(
fButtonGroup
,
new
TGHotString
(
"CB 4"
),
69
IDs
.GetUnID());
70
fRadiob
[0] =
new
TGRadioButton
(
fButtonGroup
,
new
TGHotString
(
"RB 1"
),
71
IDs
.GetUnID());
72
fRadiob
[1] =
new
TGRadioButton
(
fButtonGroup
,
new
TGHotString
(
"RB 2"
),
73
IDs
.GetUnID());
74
fButtonGroup
->Show();
75
76
fHL2
->AddFrame(
fButtonGroup
,
new
TGLayoutHints
(
kLHintsCenterX
|
kLHintsCenterY
,
77
1, 1, 1, 1));
78
AddFrame(
fHL2
);
79
80
fCheckb
[0]->Connect(
"Toggled(Bool_t)"
,
"MyButtonTest"
,
this
,
81
"SetGroupEnabled(Bool_t)"
);
82
83
TGHorizontalFrame
*
fHL3
=
new
TGHorizontalFrame
(
this
, 70, 100,
kFixedWidth
);
84
fExit
=
new
TGTextButton
(
fHL3
,
"&Exit"
,
IDs
.GetUnID());
85
fExit
->Connect(
"Clicked()"
,
"MyButtonTest"
,
this
,
"DoExit()"
);
86
fHL3
->AddFrame(
fExit
,
new
TGLayoutHints
(
kLHintsExpandX
));
87
AddFrame(
fHL3
,
new
TGLayoutHints
(
kLHintsCenterX
|
kLHintsCenterY
,1,1,1,1));
88
89
//Default state
90
fCheckb
[0]->SetOn();
91
fButtonGroup
->SetState(
kTRUE
);
92
93
SetWindowName(
"My Button Group"
);
94
MapSubwindows
();
95
Resize(GetDefaultSize());
96
MapWindow();
97
98
fButtonGroup
->SetRadioButtonExclusive(
kTRUE
);
99
fRadiob
[1]->SetOn();
100
};
101
102
MyButtonTest::~MyButtonTest()
103
{
104
// Destructor.
105
Cleanup();
106
}
107
108
void
MyButtonTest::DoExit()
109
{
110
// Exit this application via the Exit button or Window Manager.
111
// Use one of the both lines according to your needs.
112
// Please note to re-run this macro in the same ROOT session,
113
// you have to compile it to get signals/slots 'on place'.
114
115
//DeleteWindow(); // to stay in the ROOT session
116
gApplication
->
Terminate
();
// to exit and close the ROOT session
117
}
118
119
void
MyButtonTest::SetGroupEnabled(
Bool_t
on
)
120
{
121
fButtonGroup
->SetState(
on
);
122
}
123
124
void
buttongroupState
()
125
{
126
new
MyButtonTest
(
gClient
->GetRoot(),100,100);
127
}
128
kFixedWidth
@ kFixedWidth
Definition
GuiTypes.h:387
h
#define h(i)
Definition
RSha256.hxx:106
Bool_t
bool Bool_t
Definition
RtypesCore.h:63
Int_t
int Int_t
Definition
RtypesCore.h:45
UInt_t
unsigned int UInt_t
Definition
RtypesCore.h:46
kTRUE
constexpr Bool_t kTRUE
Definition
RtypesCore.h:100
ClassDef
#define ClassDef(name, id)
Definition
Rtypes.h:337
TApplication.h
gApplication
R__EXTERN TApplication * gApplication
Definition
TApplication.h:170
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
TGButtonGroup.h
TGButton.h
TGClient.h
gClient
#define gClient
Definition
TGClient.h:156
TGFrame.h
kDeepCleanup
@ kDeepCleanup
Definition
TGFrame.h:42
TGLabel.h
TGLayout.h
kLHintsCenterY
@ kLHintsCenterY
Definition
TGLayout.h:28
kLHintsCenterX
@ kLHintsCenterX
Definition
TGLayout.h:25
kLHintsExpandX
@ kLHintsExpandX
Definition
TGLayout.h:30
w
winID w
Definition
TGWin32VirtualGLProxy.cxx:39
p
winID h TVirtualViewer3D TVirtualGLPainter p
Definition
TGWin32VirtualGLProxy.cxx:51
on
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Definition
TGWin32VirtualXProxy.cxx:106
MapSubwindows
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
Definition
TGWin32VirtualXProxy.cxx:94
TGWindow.h
TString.h
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TApplication::Terminate
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
Definition
TApplication.cxx:1916
TGCheckButton
Selects different options.
Definition
TGButton.h:264
TGHorizontalFrame
A composite frame that layout their children in horizontal way.
Definition
TGFrame.h:385
TGHotString
TGHotString is a string with a "hot" character underlined.
Definition
TGString.h:42
TGLayoutHints
This class describes layout hints used by the layout classes.
Definition
TGLayout.h:50
TGMainFrame
Defines top level windows that interact with the system Window Manager.
Definition
TGFrame.h:397
TGRadioButton
Selects different options.
Definition
TGButton.h:321
TGTextButton
Yield an action as soon as it is clicked.
Definition
TGButton.h:142
TGVButtonGroup
Organizes TGButton widgets in a group with one vertical column.
Definition
TGButtonGroup.h:94
TGWindow
ROOT GUI Window base class.
Definition
TGWindow.h:23
tutorials
gui
buttongroupState.C
ROOT v6-32 - Reference Guide Generated on Sun Mar 16 2025 14:03:37 (GVA Time) using Doxygen 1.10.0