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

Detailed Description

This macro gives an example for changing text button labels anytime the Start or Pause buttons are clicked.

To run it do either:

.x buttonChangelabel.C
.x buttonChangelabel.C++
#include <TGClient.h>
#include <TGButton.h>
#include <TGFrame.h>
class MyMainFrame : public TGMainFrame {
private:
TGCompositeFrame *fCframe;
TGTextButton *fStart, *fPause, *fExit;
Bool_t start, pause;
public:
MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
~MyMainFrame() override;
// slots
void ChangeStartLabel();
void ChangePauseLabel();
ClassDef(MyMainFrame, 0)
};
void MyMainFrame::ChangeStartLabel()
{
// Slot connected to the Clicked() signal.
// It will toggle labels "Start" and "Stop".
fStart->SetState(kButtonDown);
if (!start) {
fStart->SetText("&Stop");
start = kTRUE;
} else {
fStart->SetText("&Start");
}
fStart->SetState(kButtonUp);
}
void MyMainFrame::ChangePauseLabel()
{
// Slot connected to the Clicked() signal.
// It will toggle labels "Resume" and "Pause".
fPause->SetState(kButtonDown);
if (!pause) {
fPause->SetText("&Resume");
pause = kTRUE;
} else {
fPause->SetText("&Pause");
pause = kFALSE;
}
fPause->SetState(kButtonUp);
}
MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
{
// Create a horizontal frame containing buttons
fCframe = new TGCompositeFrame(this, 170, 20, kHorizontalFrame|kFixedWidth);
fStart = new TGTextButton(fCframe, "&Start");
fStart->Connect("Clicked()", "MyMainFrame", this, "ChangeStartLabel()");
fCframe->AddFrame(fStart, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
3, 2, 2, 2));
fStart->SetToolTipText("Click to toggle the button label (Start/Stop)");
fPause = new TGTextButton(fCframe, "&Pause");
fPause->Connect("Clicked()", "MyMainFrame", this, "ChangePauseLabel()");
fPause->SetToolTipText("Click to toggle the button label (Pause/Resume)");
fCframe->AddFrame(fPause, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
3, 2, 2, 2));
pause = kFALSE;
AddFrame(fCframe, new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
fExit = new TGTextButton(this, "&Exit ","gApplication->Terminate(0)");
AddFrame(fExit, new TGLayoutHints(kLHintsTop | kLHintsExpandX,5,5,2,2));
SetWindowName("Change Labels");
Resize(GetDefaultSize());
MapWindow();
}
MyMainFrame::~MyMainFrame()
{
// Clean up all widgets, frames and layouthints that were used
fCframe->Cleanup();
Cleanup();
}
void buttonChangelabel()
{
// Popup the GUI...
new MyMainFrame(gClient->GetRoot(), 350, 80);
}
@ kFixedWidth
Definition GuiTypes.h:387
@ kHorizontalFrame
Definition GuiTypes.h:382
#define h(i)
Definition RSha256.hxx:106
bool Bool_t
Definition RtypesCore.h:63
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassDef(name, id)
Definition Rtypes.h:337
@ kButtonDown
Definition TGButton.h:54
@ kButtonUp
Definition TGButton.h:53
#define gClient
Definition TGClient.h:157
@ kLHintsCenterX
Definition TGLayout.h:25
@ 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
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:287
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
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 buttonChangelabel.C.