Root very poor in layout of TGLabels Neet Help


_ROOT Version:28.00b
_Platform:WIn 7
_Compiler:VS2008


Very frustrated with Root and poor documentation!
I have multiple TGLabels followed by TGTextEntries. The TGLabel lables don’t display well. I have to add a bunch of spaces to get the label to display. For example, if I use the following, “Tube ID” gets truncated to “Tube”.
m_pLBL_TubeID = new TGLabel(m_pOptionalDlgFrame, "Tube ID");
I have to use the following to display the ID portion.
m_pLBL_TubeID = new TGLabel(m_pOptionalDlgFrame, "Tube ID ");

Here is my code:

TGVerticalFrame *pVF = new TGVerticalFrame(this, 200,200);

		m_pOptionalDlgFrame = new TGHorizontalFrame(pVF, 40,10);

		// TubeID Labels and Field.
		m_pLBL_TubeID = new TGLabel(m_pOptionalDlgFrame, "Tube ID");
		m_pDlgTubeID = new TGTextEntry(m_pOptionalDlgFrame, "");
		m_pOptionalDlgFrame->AddFrame(m_pLBL_TubeID, new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 0, 5, 0, 0));
		m_pOptionalDlgFrame->AddFrame(m_pDlgTubeID, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 10, 0));
		pVF->AddFrame(m_pOptionalDlgFrame, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));

		// Animal Code Field.
		TGHorizontalFrame *m_pOptionalDlgFrame1 = new TGHorizontalFrame(pVF, 20,10);
		m_pLBL_AnimalCode = new TGLabel(m_pOptionalDlgFrame1, "Animal Code           ");
		m_pDialogData = new TGTextEntry(m_pOptionalDlgFrame1, "");
		m_pOptionalDlgFrame1->AddFrame(m_pLBL_AnimalCode, new TGLayoutHints(kLHintsNormal| kLHintsExpandX, 0, 0, 10, 0));
		m_pOptionalDlgFrame1->AddFrame(m_pDialogData, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 10, 0));
		pVF->AddFrame(m_pOptionalDlgFrame1, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 10, 0));

I’ve tried messing around with the TGLayoutHints, but not working without padding with a bunch of " " which I think is really poor solution.

What am I doing wrong?

Thank you,
Angel

@bellenot will help you when he will be back next week.

Hi,

What about using a TGTableLayout?

   pVF->SetLayoutManager(new TGTableLayout(pVF, 2, 2)); 

   // TubeID Labels and Field.
   m_pLBL_TubeID = new TGLabel(pVF, "Tube ID");
   m_pDlgTubeID = new TGTextEntry(pVF, "");
   pVF->AddFrame(m_pLBL_TubeID, new TGTableLayoutHints(0, 1, 0, 1, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));
   pVF->AddFrame(m_pDlgTubeID, new TGTableLayoutHints(1, 2, 0, 1, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

   // Animal Code Field.
   m_pLBL_AnimalCode = new TGLabel(pVF, "Animal Code");
   m_pDialogData = new TGTextEntry(pVF, "");
   pVF->AddFrame(m_pLBL_AnimalCode, new TGTableLayoutHints(0, 1, 1, 2, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));
   pVF->AddFrame(m_pDialogData, new TGTableLayoutHints(1, 2, 1, 2, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

Cheers, Bertrand.

Thank you!

I’m having difficultity understanding TGTableLayoutHints(0, 1, 0, 1, ….

Can follow the flow/numbering you use and referring to the root class reference for:

TGTableLayoutHints (UInt_t attach_left, UInt_t attach_right, UInt_t attach_top, UInt_t attach_bottom

Can’t follow attach_left, attach_right, attach_top, attach_bottom.

Can you explain?

Thank you,

Angel

Bertrand:

Thank you for the TGTableLaout() it helped. Although, the TGTableLayoutHints () is not very intuitive in adding additional rows and columns.

I’m still having issues in having to pad my TGLable() in order to display the label text. I’d like to know what I’m doing wrong and why I have to pad the text with so many spaces to have the test display correctly. Below is my code:

TGVerticalFrame *pVF = new TGVerticalFrame(this, 200,200);

pVF->SetLayoutManager(new TGTableLayout(pVF, 5, 2, kFALSE, 5));

// TubeID Labels and Field.

m_pLBL_TubeID = new TGLabel(pVF, "Tube ID       ");

m_pDlgTubeID = new TGTextEntry(pVF, "");

m_pDlgTubeID->SetToolTipText("Tube ID for the Animal Code and specimen.");

pVF->AddFrame(m_pLBL_TubeID, new TGTableLayoutHints(0, 1, 0, 1, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

pVF->AddFrame(m_pDlgTubeID, new TGTableLayoutHints(1, 2, 0, 1, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

// Animal Code Field.

m_pLBL_AnimalCode = new TGLabel(pVF, "Animal Code            ");

m_pDialogData = new TGTextEntry(pVF, "");

m_pDialogData->SetToolTipText("Animal Code specimen to be sorted.");

pVF->AddFrame(m_pLBL_AnimalCode, new TGTableLayoutHints(0, 1, 1, 2, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

pVF->AddFrame(m_pDialogData, new TGTableLayoutHints(1, 2, 1, 2, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

/*

m_pDialogData->SetFont(ft_l);

m_pDialogData->SetText("");

m_pDialogData->SetEditable(kFALSE);

m_pDialogData->SetEnabled(kTRUE);

m_pDialogData->SetWindowName("Bull Data");

this->EnableBullDialog(kFALSE); // hide by default

*/

// SortType Field (ListBox)

m_pLBL_SortType = new TGLabel(pVF, "Sort Type         ");

m_pDlgTubeIDSortType = new TGComboBox(pVF,90);

m_pDlgTubeIDSortType->Resize(100, 20);

m_pDlgTubeIDSortType->AddEntry("N/A", 0);

m_pDlgTubeIDSortType->AddEntry("HE", 1);

m_pDlgTubeIDSortType->AddEntry("HP", 2);

m_pDlgTubeIDSortType->AddEntry("VHP", 3);

m_pDlgTubeIDSortType->AddEntry("RES", 4);

m_pDlgTubeIDSortType->Select(0); // Select N/A

pVF->AddFrame(m_pLBL_SortType, new TGTableLayoutHints(0, 1, 2, 3, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

pVF->AddFrame(m_pDlgTubeIDSortType, new TGTableLayoutHints(1, 2, 2, 3, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

// Purity field.

m_pLBL_Purity =  new TGLabel(pVF, "Purity        ");

m_pDlgTubeIDPurity = new TGTextEntry(pVF, "");

m_pDlgTubeIDPurity->SetToolTipText("Purity of the Animal Code/specimen.");

pVF->AddFrame(m_pLBL_Purity, new TGTableLayoutHints(0, 1, 3, 4, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

pVF->AddFrame(m_pDlgTubeIDPurity, new TGTableLayoutHints(1, 2, 3, 4, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

// MachineID Mismatch field (0 fail,1 success)

m_pLBL_MachineID =  new TGLabel(pVF, "Machine ID\nMatch                    ");

m_pDlgTubeIDMachineIDMatch = new TGTextEntry(pVF, "");

m_pDlgTubeIDMachineIDMatch->SetToolTipText("Machine ID specifies if the Animal Code specimen is allowed to be sorted on this machine.");

pVF->AddFrame(m_pLBL_MachineID, new TGTableLayoutHints(0, 1, 4, 5, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

pVF->AddFrame(m_pDlgTubeIDMachineIDMatch, new TGTableLayoutHints(1, 2, 4, 5, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

AddFrame(pVF, new TGLayoutHints(kLHintsCenterX, 0, 0, 10, 10));

pVF->Layout();

pVF->MapSubwindows();

Hi,

Well, the example I posted was showing how to solve this issue… Did you try?

I’ll check tomorrow. In the meanwhile, please take a look at: Posting code? Read this first!

Cheers, Bertrand.

Hi, yes, I changed my code to use your suggestion. See the sample code below:


TGVerticalFrame *pVF = new TGVerticalFrame(this, 200,200);

                        pVF->SetLayoutManager(new TGTableLayout(pVF, 5, 2, kFALSE, 5));

                        // TubeID Labels and Field.

                        m_pLBL_TubeID = new TGLabel(pVF, "Tube ID       ");

                        m_pDlgTubeID = new TGTextEntry(pVF, "");

                        m_pDlgTubeID->SetToolTipText("Tube ID for the Animal Code and specimen.");

                        pVF->AddFrame(m_pLBL_TubeID, new TGTableLayoutHints(0, 1, 0, 1, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

                        pVF->AddFrame(m_pDlgTubeID, new TGTableLayoutHints(1, 2, 0, 1, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

                        // Animal Code Field.

                        m_pLBL_AnimalCode = new TGLabel(pVF, "Animal Code            ");

                        m_pDialogData = new TGTextEntry(pVF, "");

                        m_pDialogData->SetToolTipText("Animal Code specimen to be sorted.");

                        pVF->AddFrame(m_pLBL_AnimalCode, new TGTableLayoutHints(0, 1, 1, 2, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

                        pVF->AddFrame(m_pDialogData, new TGTableLayoutHints(1, 2, 1, 2, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

/*

                        m_pDialogData->SetFont(ft_l);

                        m_pDialogData->SetText("");

                        m_pDialogData->SetEditable(kFALSE);

                        m_pDialogData->SetEnabled(kTRUE);

                        m_pDialogData->SetWindowName("Bull Data");

                        this->EnableBullDialog(kFALSE); // hide by default

*/

                        // SortType Field (ListBox)

                        m_pLBL_SortType = new TGLabel(pVF, "Sort Type         ");

                        m_pDlgTubeIDSortType = new TGComboBox(pVF,90);

                        m_pDlgTubeIDSortType->Resize(100, 20);

                        m_pDlgTubeIDSortType->AddEntry("N/A", 0);

                        m_pDlgTubeIDSortType->AddEntry("HE", 1);

                        m_pDlgTubeIDSortType->AddEntry("HP", 2);

                        m_pDlgTubeIDSortType->AddEntry("VHP", 3);

                        m_pDlgTubeIDSortType->AddEntry("RES", 4);

                        m_pDlgTubeIDSortType->Select(0); // Select N/A

                        pVF->AddFrame(m_pLBL_SortType, new TGTableLayoutHints(0, 1, 2, 3, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

                        pVF->AddFrame(m_pDlgTubeIDSortType, new TGTableLayoutHints(1, 2, 2, 3, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

                        // Purity field.

                        m_pLBL_Purity =  new TGLabel(pVF, "Purity        ");

                        m_pDlgTubeIDPurity = new TGTextEntry(pVF, "");

                        m_pDlgTubeIDPurity->SetToolTipText("Purity of the Animal Code/specimen.");

                        pVF->AddFrame(m_pLBL_Purity, new TGTableLayoutHints(0, 1, 3, 4, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

                        pVF->AddFrame(m_pDlgTubeIDPurity, new TGTableLayoutHints(1, 2, 3, 4, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

                        // MachineID Mismatch field (0 fail,1 success)

                        m_pLBL_MachineID =  new TGLabel(pVF, "Machine ID\nMatch                    ");

                        m_pDlgTubeIDMachineIDMatch = new TGTextEntry(pVF, "");

                        m_pDlgTubeIDMachineIDMatch->SetToolTipText("Machine ID specifies if the Animal Code specimen is allowed to be sorted on this machine.");

                        pVF->AddFrame(m_pLBL_MachineID, new TGTableLayoutHints(0, 1, 4, 5, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

                        pVF->AddFrame(m_pDlgTubeIDMachineIDMatch, new TGTableLayoutHints(1, 2, 4, 5, kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));

                        AddFrame(pVF, new TGLayoutHints(kLHintsCenterX, 0, 0, 10, 10));

I don’t see any problem with your code (table_layout.C (3.1 KB)) when removing all spaces in the labels:

image

Note that I’m using ROOT 5.34/39
Cheers, Bertrand.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.