TGButtonGroup

Hi,

I have a couple of TGButtonGroups as part of a TGCompositeFrame somewhere in a hierarchy of TGCompositeFrames. Depending on user’s action, the number of buttons shown is variable, and thus I’d like to be able to remove/add buttons after the initial layout has been done.
I do not understand what sequence of calls (of whatever Remove(), Layout(), Resize(), MapSubwindows(), MapWindow() ?) I should code to properly update the TGButtonGroups. Tried a number of things that all ended up in a seg. viol.
I guess my main problem is that I do not understand clearly what all those methods are supposed to do exactly :wink:

Could somebody explains ?

Regards,

Hi,

Instead of removing/inserting buttons you may create the button groups containing all necessary buttons from the beginning and enable/disable some of them according to user interactions. This way is considered as the better one because users are informed visually about all set of options/attributes and they see under what conditions some are not available. All this is a theory, i.e. rules to follow in the GUI design and may not apply for your specific case.

I can create an example tomorrow, if you still need it. It will be good if you provide details which sequence of methods caused SegV. In any case the SegV should be fixed (it looks like missing protection in some methods).

Cheers, Ilka

Hi,

I do not know beforehand the list of buttons that are valid for a given view, hence the need to be “dynamic”.

I’ll try to get a condensed version of my program showing the problem tomorrow.

And yes, if you get some time, I’d like to see a working example, thanks a lot,

Regards,

Hi,

I hope you have used the Show() method of your TGButtonGroup to display it. Please try the folloing code for adding a button to the group: TGCheckButton *cb = new TGCheckButton(fButtonGroup, new TGHotString("CB New"), 99); fButtonGroup->Insert(cb, 99); //here 99 is hardcoded button id fButtonGroup->Show(); Layout(); //call Layout of the main application window For removing: TGButton *bt = fButtonGroup->Find(99); if (bt) { fButtonGroup->Remove(bt); Layout(); }Let me know the result.

Cheers, Ilka

Hi,

Actually I did forget the Show(). But there’s more to it : I need to call DestroyWindow of the remove buttons, otherwise, when I decrease the number of buttons, I have one leftover button (on the bottom of the group, right on the group bottom line). Please see attached example (if you uncomment line 14, behavior seems to be good, otherwise it’s not).
BTW, do I need to delete the button when I do a Remove() or do the Remove takes care of that too ?

Regards,

PS: Using root 5.16/00 for macosx (intel)
testGroupButton.C (1.48 KB)

Hi,

Many thanks for your example. I will investigate further and will let you know.

Best regards, Ilka

Hi,

I have added a call to DestroyWindow of removed button in TGButtonGroup::Remove(TGButton *button) method. This way your example works fine with CVS head with no need to call DestroyWindow on line 14. Thank you for pointing out that behavior.

Yes, you need to delete the removed button. Also you need to delete all remaining buttons of TGButtonGroup when you delete it.

Cheers, Ilka