Changing TGTextBox button labels

I just can’t seem to get this right…for the life of me I can’t get SetText() to work. I want this to change the labels on the buttons when either the first or second are pressed. It sets the text fine when they’re created but for some reason it doesn’t here and I’m not sure why. Any help would be greatly appreciated.

// BUTTONS
// -------
if ((GET_MSG (msg) == kC_COMMAND) && (GET_SUBMSG (msg) == kCM_BUTTON)) {
switch (parm1) {
case kButtonStart: // Start Button
{
if (fControlStart) {
fControlStart = false;
fControlPause = true;
fCalcConf->fPause = false;
fControlButton[1]->SetState (kButtonUp); // Enable PAUSE
fControlButton[0]->SetText (kHotControlButtonText[3]); // Change START to STOP
fControlButton[1]->SetText (kHotControlButtonText[1]); // Change RESUME to PAUSE

           ReadCalcConf();
           ReadPlotConf();
           ReadOutConf();

// fStartTime = time(time);
break;
}
else {
fControlStart = true;
fCalcConf->fPause = true;
fControlButton[1]->SetState (kButtonDisabled); // Disable PAUSE
if (fControlPause = false) {
fControlPause = true;
}
/* fControlButton[1]->SetText (new TGHotString (kControlButtonText[1])); // Change RESUME to PAUSE
fControlButton[0]->SetText (new TGHotString (kControlButtonText[0])); // Change STOP to START
*/
break;
}

     }
   case kButtonPause:   // Stop Button
     {
    if (fControlPause) {
       fControlPause = false;
       fControlStart = true;
       fCalcConf->fPause = false;

/* fControlButton[0]->SetText (new TGHotString (kControlButtonText[0])); // Change STOP to START
fControlButton[1]->SetText (new TGHotString (kControlButtonText[4])); // Change PAUSE to RESUME
*/
break;
}

    else {
       fControlPause = true;
       fControlStart = false;
           fCalcConf->fPause = true;

/* fControlButton[0]->SetText (new TGHotString (kControlButtonText[3])); // Change START to STOP
fControlButton[1]->SetText (new TGHotString (kControlButtonText[1])); // Change RESUME to PAUSE
*/
break;
}
}
case kButtonQuit: // Quit Button
{
CloseWindow();
break;
}

Hi,

From the code you have sent I can guess about the use of some variables.
The attached macro buttonsettext.C contains an example of how to change the text button labels on button click. I made it as simple as possible. There are three buttons: Start, Pause and Exit. Start label changes to Stop when the button is clicked, Pause label changes to Resume etc. Click on Exit for quit.

In the macro is used the signals/slots mechanism. It is easier and faster for programming. The two slots do the same thing but I have left them separately to give you the possibility to implement different actions in addition.

You can read more about signals/slots on page 403 of the ROOT User’s Guide at:
root.cern.ch/root/doc/RootDoc.html
(the chapter “Writing a Graphical User Interface”)

Cheers, Ilka
buttonsettext.C (3.11 KB)