RootTalk


ROOT Discussion Forums

Create multiple columns of TGNumberEntry

Discuss your own ROOT application.

Moderator: rootdev

Create multiple columns of TGNumberEntry

Postby fed27 » Wed Jan 21, 2015 15:23

Hi.I'm making a GUI in order to produce a output file. I would like to create more columns of TGNumberEntry and for each column a different number of TGNumberEntry.
i try in this way but it puts the two columns one below the other but i want them side by side

Code: Select all
#include <iostream>
#include <stdlib.h>

class MyMainFrame : public TGMainFrame {

private:
   TGCompositeFrame    *fHor1,*f2,*f3,*c1,*c2,*exitandsave,*s1;
   TGTextButton        *fExit,*Save;
   TGGroupFrame        *fGframe;
   TGNumberEntry       *fNumber,*fNumber2,*fNumber3,*fNumberc2;
   TGLabel             *fLabel,*fLabel2,*fLabel3,*fLabelc2;

public:
   MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
   virtual ~MyMainFrame();
   void Save1();
   
   ClassDef(MyMainFrame, 0)
};
                         
MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h)
   : TGMainFrame(p, w, h)
{
   std::ofstream ofs;
   ofs.open ("test.inp");
   
   ///////////////////////////
   c2=new TGVerticalFrame(this,60,400);
   c1=new TGVerticalFrame(this,60,400);
   
   //c2=new TGHVerticalFrame(this,60,400);
   fHor1 = new TGHorizontalFrame(c1, 150, 20, kFixedWidth);
   f2=new TGHorizontalFrame(c1, 150, 20, kFixedWidth);
   f3=new TGHorizontalFrame(c1, 150, 20, kFixedWidth);
   s1=new TGHorizontalFrame(c2, 150, 20, kFixedWidth);
   exitandsave=new TGHorizontalFrame(c1, 150, 20, kFixedWidth);
 
   ////////////////exit and save
   
   
   fExit = new TGTextButton(exitandsave, "&Exit", "gApplication->Terminate(0)");
   Save= new TGTextButton(exitandsave,"&Salva");
   Save->Connect("Clicked()","MyMainFrame",this,"Save1()");
   exitandsave->AddFrame(Save, new TGLayoutHints(kLHintsBottom| kLHintsLeft ,4, 4, 4, 4));
   exitandsave->AddFrame(fExit, new TGLayoutHints(kLHintsBottom | kLHintsLeft , 4, 4, 4, 4));
   
   c1->AddFrame(exitandsave,new TGLayoutHints(kLHintsBottom | kLHintsRight, 5, 5, 5, 5));
   
   
   ////////////////////////////
   
     
   fNumber = new TGNumberEntry(fHor1, 0, 9,999, TGNumberFormat::kNESInteger,
                                               TGNumberFormat::kNEANonNegative,
                                               TGNumberFormat::kNELLimitMinMax,
                                               0, 99999);
   fHor1->AddFrame(fNumber, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
   fLabel = new TGLabel(fHor1, "No inp.");
 
   fHor1->AddFrame(fLabel, new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 5, 5));
   
   c1->AddFrame(fHor1,new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 5, 1));
   ///////////////////////
   
   fNumber2 = new TGNumberEntry(f2, 0, 9,999, TGNumberFormat::kNESInteger,
                                               TGNumberFormat::kNEANonNegative,
                                               TGNumberFormat::kNELLimitMinMax,
                                               0, 99999);
   f2->AddFrame(fNumber2, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
   fLabel2 = new TGLabel(f2, "2222222");
   f2->AddFrame(fLabel2, new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 5, 5));
   c1->AddFrame(f2,new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 5, 1));
   ///////////////////
   fNumber3 = new TGNumberEntry(f3, 0, 9,999, TGNumberFormat::kNESInteger,
                                               TGNumberFormat::kNEANonNegative,
                                               TGNumberFormat::kNELLimitMinMax,
                                               0, 99999);
   f3->AddFrame(fNumber3, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
   fLabel3 = new TGLabel(f3, "2222222");
   f3->AddFrame(fLabel3, new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 5, 5));
   c1->AddFrame(f3,new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 5, 1));
 
   //(fNumber->GetNumberEntry())->Connect("ReturnPressed()", "MyMainFrame", this,"DoSetlabel()");
   
   //fGframe = new TGGroupFrame(this, "Value"); 
   
 
 
   //////////////metti la prima colonna
   
   AddFrame(c1,new TGLayoutHints(kLHintsBottom | kLHintsLeft, 5, 5, 5, 5));
   
   ///////////////////// seconda colonna
   
   
   fNumberc2 = new TGNumberEntry(s1, 0, 9,999, TGNumberFormat::kNESInteger,
                                               TGNumberFormat::kNEANonNegative,
                                               TGNumberFormat::kNELLimitMinMax,
                                               0, 99999);
   s1->AddFrame(fNumberc2, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
   fLabelc2 = new TGLabel(s1, "No inp.");
 
   s1->AddFrame(fLabelc2, new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 5, 5));
   
   c2->AddFrame(s1,new TGLayoutHints(kLHintsBottom | kLHintsRight, 5, 5, 5, 5));
   
   ////////////////////////// fine seconda colonna
   
   AddFrame(c2,new TGLayoutHints(kLHintsBottom | kLHintsRight, 5, 5, 5, 5));
   
   /////////////////
   
   SetCleanup(kDeepCleanup);
   SetWindowName("Number Entry");
   MapSubwindows();
   Resize(GetDefaultSize());
   MapWindow();
}

MyMainFrame::~MyMainFrame()
{
   // Destructor.
   
   Cleanup();
}


void MyMainFrame::Save1()
{
   // Slot method connected to the ValueSet(Long_t) signal.
   // It displays the value set in TGNumberEntry widget.
   std::ofstream ofs;
   ofs.open ("test.inp");
   ofs<<fNumber->GetNumberEntry()->GetIntNumber()<<","<<fNumber2->GetNumberEntry()->GetIntNumber()<<","
   <<fNumber3->GetNumberEntry()->GetIntNumber()<<endl;
 
   // Parent frame Layout() method will redraw the label showing the new value.
   //fGframe->Layout();
}

void esempio()
{
   new MyMainFrame(gClient->GetRoot(), 200, 200);
}
 


thank you
fed27
 
Posts: 10
Joined: Thu Jun 26, 2014 9:34

Re: Create multiple columns of TGNumberEntry

Postby bellenot » Wed Jan 21, 2015 17:32

Hi,

If you want them side by side, you must use a TGHorizontalFrame as container... For example, in your case:
Code: Select all
MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h)
   : TGMainFrame(p, w, h, kMainFrame | kHorizontalFrame)

Cheers, Bertrand.
User avatar
bellenot
 
Posts: 1857
Joined: Mon Sep 01, 2003 10:57
Location: CERN


Return to My ROOT App

Who is online

Users browsing this forum: No registered users and 1 guest