TGTableLayout, how to clear?

I have run into a GUI related problem using TGTableLayout. I am hoping to get some help here…

My GUI application has a TGComposite frame, consisting of a bunch of TGTextButtons collected in a TObjArray. Their layout is managed by TGTableLayout. The twist is that the list of buttons is user selectable (Another part of the GUI takes care of the user managing the TObjArray of buttons to display).

The problem is as follows: Say initially Eight TGTextButtons are displayed. The user then changes the selection, and only Six buttons are to be displayed (the remaining two are deleted and removed from the TObjArray). In that case the space occupied by the last two buttons is not cleanly redrawn - the background used by the now deleted buttons remains on the frame :frowning:

I take care to do ‘Layout(); MapSubwindows()’ in the routine that re-displays the buttons, and do a gClient->NeedRedraw() for each of the buttons and the TGCompositeFrame, to no avail.

I can post a code sample if anyone is interested - but it will require some work to pull out just this piece from the GUI, so I was hoping to get some help before that!


Without having an example I can say that the better way to hide/show widgets is to group them in separate containers that in some conditions could be shown or hidden. For TGTextButton objects you could set only the the state kButtonDisabled to make them inaccessible but they should not be deleted.

Best regards, Ilka

After digging around a little bit - I solved my problem. I am posting the resolution here so that others can benefit (hopefully!)

The solution was:

Before deleting the TGTextButton objects managed by the TGTableLayout, I had to do an explicit DestroyWindow on each of the TGTextButton’s. Then the nasty grey blob left behind by the removed
TGTextButton finally disappeared!
the order that worked was:

TIter next(fListOfButtons);
while(TGTextButton *b = (TGTextButton *)next()) 
      delete b;