Prevent TGTableLayout from shrinking the Frame to min. size

Hi,
i have a small problem, maybe someone can help me:
I made a class derived from TGCompositeFrame and used as Layout-Manager TableLayout. The purpose of the Class is to put together a Label, NumberEntry and additionally 2 to 4 Buttons in a Matrix with 2 rows and 4 Columns (Label (over 2 rows), NumberEntry (over 2 rows), 2 Buttons, 2 Buttons). Because I will have a lot of theses CompositeFrames in one Column I want them to have all the same width (by expanding the Label-Column), which i tell them when i call the ctor.
The Problem is, that -i dont know when exactly- the width of the CompositeFrame shrinks to its minimal size. Can I tell the LayoutManager not to shrink?

Thanks for your Help and sorry for the english, i hope it is understandable :slight_smile:

Maxi

Hi Maxi,

You can use the kFixedSize attribute of your TGCompoositeFrame, e.g: frame->ChangeOptions(frame->GetOptions() | kFixedSize);
This flag let you set the size of the frame, but avoid automatic resizing.
If this doesn’t help, or if I misunderstood your problem, please post a running macro showing the problem.

Cheers,
Bertrand.

Thank you Bertrand for your Help! Now the size of the frame is right, but now it “mixes” the order of the Widgets which are in the frame. It puts all of them (Label, NumberEntry, Buttons) always to the same place, which is not the place I told them in the TGTabelLayoutHints. And neither it does react to flags like kLHintsExand/Shrink… etc.
Any Idea why this happens?

Thanks!
Maxi

Hi Maxi,

No idea… The best way to solve the problem is to look at your code. So please post a running macro showing the problem. This will also save our time :wink:

Cheers, Bertrand.

Okay, i will try to build a running macro, but it will take some time…
But the Problem at the Moment is, that TGTableLayout simply doesnt work with kFixedSize: When i use the command you gave me (even if i use it after Adding all the widgets with TableLayout, there are no rows, only one column and the widgets are in the order i added them, not in the order given by the TGTableLayoutHints. So i suppose that TableLayout simply stopped working and the Layout is done without LayoutManager (or just the simplest one).

Maxi

OK, I’ll try and keep you in touch.
Cheers, Bertrand.

Problem: The two LabelEntrys (l1, l2) always shrink to minimal size, but I want them to have the size given to them in the ctor.
If I use kFixedSize, the TableLayout-Manager doesnt work.

My Aim is that the NumberEntry in LabelEntry has a defined size (here 30 digits), the two Buttons have minimal size and
the Lable expands until the LabelEntry has the width given to it in the ctor (here 500 or 600).

[code]

// TableLayoutMacro.C

//Problem: The two LabelEntrys (l1, l2) always shrink to minimal size, but I want them to have the size given to them in the ctor.
//If I use kFixedSize, the TableLayout-Manager doesnt work.
//
//My Aim is that the NumberEntry in LabelEntry has a defined size (here 30 digits), the two Buttons have minimal size and
//the Lable expands until the LabelEntry has the width given to it in the ctor (here 500 or 600).

//(Sometimes this Macro doesnt exit correctly, but i dont know why and how to fix it. But thats not my main Problem)

#include “TGLabel.h”
#include “TGNumberEntry.h”
#include “TGButton.h”
#include “TGTableLayout.h”
#include “TGFrame.h”

class LabelEntry : public TGCompositeFrame{
public:
TGLabel * fLabel;
TGNumberEntry * fNumberEntry;
TGTextButton * fTextButton1, * fTextButton2;
TGTableLayout * tabLayout;

ClassDef(LabelEntry, 0)

public:
LabelEntry(const TGWindow * parent, Int_t Width, Int_t Height); //ctor

};

ClassImp(LabelEntry)

LabelEntry::LabelEntry(const TGWindow * parent, Int_t Width, Int_t Height): TGCompositeFrame(parent, Width, Height){

this->Resize(Width,Height);

tabLayout=new TGTableLayout(this, 2,5, kFALSE);
this->SetLayoutManager(tabLayout);

fLabel = new TGLabel(this, "Label");
fNumberEntry = new TGNumberEntry(this, 0., 30, 1);
fTextButton1 = new TGTextButton(this, "TextButton");
fTextButton2 = new TGTextButton(this, "TextButton2");

this->AddFrame(fLabel, new TGTableLayoutHints(0,1,0,2,
    	                            kLHintsExpandX|kLHintsExpandY 
    	                           | kLHintsShrinkX|kLHintsShrinkY |
				    kLHintsCenterX|kLHintsCenterY
				   | kLHintsFillX|kLHintsFillY
				     ,1,1,1,1));
this->AddFrame(fNumberEntry, new TGTableLayoutHints(1,2,0,2,
    	                            kLHintsExpandX|kLHintsExpandY 
    	                           | kLHintsShrinkX|kLHintsShrinkY |
				    kLHintsCenterX|kLHintsCenterY
				   | kLHintsFillX|kLHintsFillY
				     ,1,1,1,1));
this->AddFrame(fTextButton1, new TGTableLayoutHints(2,3,0,1,
    	                            kLHintsExpandX|kLHintsExpandY 
    	                           | kLHintsShrinkX|kLHintsShrinkY |
				    kLHintsCenterX|kLHintsCenterY
				   | kLHintsFillX|kLHintsFillY
				     ,1,1,1,1));
this->AddFrame(fTextButton2, new TGTableLayoutHints(2,3,1,2,
    	                            kLHintsExpandX|kLHintsExpandY 
    	                           | kLHintsShrinkX|kLHintsShrinkY |
				    kLHintsCenterX|kLHintsCenterY
				   | kLHintsFillX|kLHintsFillY
				     ,1,1,1,1));

//this->ChangeOptions(this->GetOptions() | kFixedSize);				// <= why doesnt it work?

}

void start(){
TGMainFrame * w = new TGMainFrame (gClient->GetRoot(), 800, 800);

LabelEntry *l1, *l2;
l1= new LabelEntry(w, 500,60);
l2= new LabelEntry(w, 600, 70);
w->AddFrame(l1);
w->AddFrame(l2);

w->SetWindowName("Example Macro");
w->MapSubwindows();
w->Resize();
w->Resize(800, 800);
w->MapWindow();

}[/code]

Thanks for the Help!!
Maxi

Hi Maxi,

So indeed, the fixed size flag doesn’t work in this case…
Anyway, could you still post a macro (or just the method where you build your GUI) so I can take a look and try to solve your original problem?

Cheers,
Bertrand.

Hi Bertrand,
we posted at the same time i guess?
Or, if you need another makro, what shoud it be like?

Cheers,
Maxi

Hi Maxi,

Yes, sorry, I didn’t see your post and didn’t have any notification…
I’ll try to come with a solution asap and let you know.

Cheers,
Bertrand.

Hi Maxi,

OK, I see the problems. I will investigate these issues, but for the time being, please try with something like this:

[code]LabelEntry::LabelEntry(const TGWindow * parent, Int_t Width, Int_t Height) :
TGCompositeFrame(parent, Width, Height)
{

tabLayout=new TGTableLayout(this, 2,5, kFALSE);
SetLayoutManager(tabLayout);

fLabel = new TGLabel(this, “Label”);
fLabel->ChangeOptions(fLabel->GetOptions() | kFixedWidth);
fNumberEntry = new TGNumberEntry(this, 0., 30, 1);
fTextButton1 = new TGTextButton(this, “TextButton”);
fTextButton2 = new TGTextButton(this, “TextButton2”);

AddFrame(fLabel, new TGTableLayoutHints(0,1,0,2,
kLHintsExpandX | kLHintsExpandY |
// kLHintsShrinkX | kLHintsShrinkY |
kLHintsCenterX | kLHintsCenterY |
kLHintsFillX | kLHintsFillY,
1, 1, 1, 1));
AddFrame(fNumberEntry, new TGTableLayoutHints(1,2,0,2,
kLHintsExpandX | kLHintsExpandY |
// kLHintsShrinkX | kLHintsShrinkY |
kLHintsCenterX | kLHintsCenterY |
kLHintsFillX|kLHintsFillY,
1, 1, 1, 1));
AddFrame(fTextButton1, new TGTableLayoutHints(2,3,0,1,
kLHintsExpandX | kLHintsExpandY |
// kLHintsShrinkX | kLHintsShrinkY |
kLHintsCenterX | kLHintsCenterY |
kLHintsFillX | kLHintsFillY,
1, 1, 1, 1));
AddFrame(fTextButton2, new TGTableLayoutHints(2,3,1,2,
kLHintsExpandX | kLHintsExpandY |
// kLHintsShrinkX | kLHintsShrinkY |
kLHintsCenterX | kLHintsCenterY |
kLHintsFillX | kLHintsFillY,
1, 1, 1, 1));

Layout();
Resize(Width, Height);
}[/code]
And please let me know if it does what you want.

Cheers,
Bertrand.

Ok, Thank you very much!!
On Wednesday I can try it out and will let your know if it works.

Cheers,
Maxi

Hi Bertrand,

It works and does what I want, thank you very much!!

Cheers,
Maxi

Hi,

one last question.
It works fine now, but still I dont understand well, why. The main two things which I had to change were to add

and

both in the Ctor of my LabelEntry Class.
Maybe you could explain it to me shorty?

Thank you very much!

Cheers,
Maxi

Hi Maxi,

Glad to know your problem is solved! :smiley:
And this line:fLabel->ChangeOptions(fLabel->GetOptions() | kFixedWidth); is needed to not allow the automatic layout mechanism to shrink it (by default the label width is equal to its text length)
And Layout() is needed to properly compute layout and position of all sub-windows.

Cheers, Bertrand.