Hi Fons, Thank you for your quick help. Unfortunately, the TGNumberEntry class does not have a member SetFocus(). So I changed from TGNumberEntry to TGTextEntry and converted the strings to numbers after reading them. But now when I run the program, I get the following error message: Error in <TQObject::CheckConnectArgs>: slot FChangeFocus() does not exist I believe that I included all the necessary function calls, judging from you example. Do you know what this means? Thanks, Michael Gericke On Wed, 2003-02-12 at 16:04, Fons Rademakers wrote: > Hi Michael, > > use the SetFocus() method of TGTextEntry of which TGNumberEntry > derives. See the attached example. > > Cheers, Fons. > > > On Wed, 2003-02-12 at 22:58, Michael T. Gericke wrote: > > Hi, > > > > I was wondering if anyone knows how to force a dialog box > > (TGTransientFrame) to switch focus from one of its widgets > > (say a TGNumberEntry widget) to another using the "Tab" > > button.... > > > > > > Thanks, > > > > Michael Gericke > -- > Org: CERN, European Laboratory for Particle Physics. > Mail: 1211 Geneve 23, Switzerland > E-Mail: Fons.Rademakers@cern.ch Phone: +41 22 7679248 > WWW: http://root.cern.ch/~rdm/ Fax: +41 22 7679480 > ---- > > > //--------------------------------------// > // macro gui1.C // > //--------------------------------------// > #include <stdio.h> > #include <stdlib.h> > #include <iostream.h> > > #include <TROOT.h> > #include <TApplication.h> > #include <TVirtualX.h> > > #include <RQ_OBJECT.h> > #include <TGFrame.h> > #include <TGMenu.h> > #include <TGTextEntry.h> > #include <TGTextBuffer.h> > #include <TGListBox.h> > #include <TGFileDialog.h> > #include <TSystem.h> > #include <TEnv.h> > > > const char *filetypes[] = { "All files", "*", > "ROOT files", "*.root", > "ROOT macros", "*.C", > 0, 0 }; > > class TNewDlog { > > RQ_OBJECT() > > private: > TGMainFrame *fMain; > TGCompositeFrame *fFrameLT; > TGGroupFrame *fFrameInfo; > TGTextEntry *fNameF; > TGTextBuffer *fBufF; > TGTextEntry *fNameL; > TGTextBuffer *fBufL; > TGGroupFrame *fFrameDir; > // TGListBox *fDir; > TGTextEntry *fDir; > TGTextBuffer *fBufDir; > TGButton *fBrowseBtn; > TGCompositeFrame *fFrameLB; > TGButton *fOkBtn; > TGButton *fCancelBtn; > > public: > TNewDlog(const TGWindow *vWindow, > UInt_t vWidth, UInt_t vHeight, UInt_t vOptions = > kVerticalFrame); > virtual ~TNewDlog(); > > // slots > void FCloseWindow(); > void FBrowse(); > void FPressOK(); > void FCancel(); > void FChangeFocus(); > }; > > > TNewDlog::TNewDlog(const TGWindow *vWindow, > UInt_t vWidth, UInt_t vHeight, UInt_t > vOptions) > { > fMain = new TGMainFrame(vWindow, vWidth, vHeight, vOptions); > fMain->Connect("CloseWindow()", "TNewDlog", this, "FCloseWindow()"); > > // FrameLT for subframes > fFrameLT = new TGCompositeFrame(fMain, 200, 20, kVerticalFrame); > fMain->AddFrame(fFrameLT, new TGLayoutHints(kLHintsLeft | > kLHintsTop)); > > // Subframe Project Info > fFrameInfo = new TGGroupFrame(fFrameLT, "Author Info", > kVerticalFrame); > // fFrameInfo->SetLayoutManager(new TGTableLayout(fFrameInfo,2,2)); > //error > fFrameInfo->SetLayoutManager(new TGMatrixLayout(fFrameInfo,0,2,10)); > fFrameLT->AddFrame(fFrameInfo, > new TGLayoutHints(kLHintsTop | kLHintsLeft | > kLHintsExpandX,5,5,5,5)); > > fFrameInfo->AddFrame(new TGLabel(fFrameInfo,new TGString("First > Name")), > new TGLayoutHints(kLHintsTop | kLHintsLeft)); > > fNameF = new TGTextEntry(fFrameInfo, fBufF = new TGTextBuffer(100), > -1); > fNameF->Connect("ReturnPressed()", "TNewDlog", this, "FPressOK()"); > fNameF->Connect("TabPressed()", "TNewDlog", this, "FChangeFocus()"); > fFrameInfo->AddFrame(fNameF, > new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2)); > > fNameF->Resize(250, fNameF->GetDefaultHeight()); > > fFrameInfo->AddFrame(new TGLabel(fFrameInfo,new TGString("Last > Name")), > new TGLayoutHints(kLHintsTop | kLHintsLeft)); > > fNameL = new TGTextEntry(fFrameInfo, fBufL = new TGTextBuffer(100), > -1); > fNameL->Connect("ReturnPressed()", "TNewDlog", this, "FPressOK()"); > fNameL->Connect("TabPressed()", "TNewDlog", this, "FChangeFocus()"); > fFrameInfo->AddFrame(fNameL, > new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2)); > > fNameL->Resize(250, fNameL->GetDefaultHeight()); > > // Subframe Directory > fFrameDir = new TGGroupFrame(fFrameLT, "Directory", > kHorizontalFrame); > fFrameLT->AddFrame(fFrameDir, > new TGLayoutHints(kLHintsTop | kLHintsLeft | > kLHintsExpandX,5, 5, 5, 5)); > > fDir = new TGTextEntry(fFrameDir, fBufDir = new TGTextBuffer(255), > -1); > fDir->Connect("ReturnPressed()", "TNewDlog", this, "FPressOK()"); > fDir->Connect("TabPressed()", "TNewDlog", this, "FChangeFocus()"); > // fDir = new TGListBox(fFrameDir,-1); > fDir->Resize(400,20); > char tmp[255]; > sprintf(tmp,"%s",gSystem->WorkingDirectory()); > fDir->SetText(tmp); > // fDir->AddEntry(tmp,1); > fFrameDir->AddFrame(fDir, new > TGLayoutHints(kLHintsLeft|kLHintsTop,2,2,2,2)); > > fBrowseBtn = new TGTextButton(fFrameDir, "&Browse...", 1); > fBrowseBtn->Connect("Clicked()", "TNewDlog", this, "FBrowse()"); > fFrameDir->AddFrame(fBrowseBtn, new TGLayoutHints(kLHintsRight | > kLHintsTop)); > > // FrameLB for OK, Cancel > fFrameLB = new TGHorizontalFrame(fMain, 200, 20, kFixedWidth); > fMain->AddFrame(fFrameLB, new TGLayoutHints(kLHintsLeft | > kLHintsBottom)); > > fOkBtn = new TGTextButton(fFrameLB, "&OK", 1); > fOkBtn->Connect("Clicked()", "TNewDlog", this, "FPressOK()"); > //fOkBtn->Resize(150,20); // does not work > fFrameLB->AddFrame(fOkBtn, > new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, > 5, 5, 5, 5)); > > fCancelBtn = new TGTextButton(fFrameLB, "&Cancel", 1); > fCancelBtn->Connect("Clicked()", "TNewDlog", this, "FCancel()"); > fFrameLB->AddFrame(fCancelBtn, > new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, > 5, 5, 5, 5)); > > fFrameLB->Resize(150, fOkBtn->GetDefaultHeight()); > > fMain->MapSubwindows(); > fMain->Resize(fMain->GetDefaultSize()); > fMain->SetWMPosition(140,120); > fMain->Move(140,120); > // fMain->Resize(400,220); > > fMain->SetWindowName("New Dialog"); > > fMain->MapWindow(); > }//Constructor > > //----------------------------------------------------------------------// > > TNewDlog::~TNewDlog() > { > delete fOkBtn; delete fCancelBtn; delete fFrameLB; > delete fBrowseBtn; delete fDir; delete fFrameDir; > delete fNameL; delete fNameF; delete fFrameInfo; > delete fFrameLT; > > delete fMain; > }//Destructor > > //----------------------------------------------------------------------// > > void TNewDlog::FCloseWindow() > { > delete this; > }//FCloseWindow > > //----------------------------------------------------------------------// > > void TNewDlog::FBrowse() > { > printf("Browse\n"); > > TGFileInfo fi; > fi.fFileTypes = filetypes; > fi.fIniDir = StrDup(fBufDir->GetString()); > printf("fIniDir = %s\n", fi.fIniDir); > new TGFileDialog(gClient->GetRoot(), fMain, kFDOpen, &fi); > printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir); > fDir->SetText(fi.fIniDir); > }//FBrowseProject > > //----------------------------------------------------------------------// > > void TNewDlog::FCancel() > { > // Clear entries > fBufF->Clear(); > fBufL->Clear(); > > printf("Cancel\n"); > }//FCancel > > //----------------------------------------------------------------------// > > void TNewDlog::FPressOK() > { > cout << "First Name: " << fBufF->GetString() << endl; > cout << "Last Name: " << fBufL->GetString() << endl; > cout << "Directory: " << fBufDir->GetString() << endl; > > fMain->SendCloseMessage(); > }//FPressOK > > //----------------------------------------------------------------------// > > void TNewDlog::FChangeFocus() > { > if (gTQSender == fNameF) > fNameL->SetFocus(); > > if (gTQSender == fNameL) > fDir->SetFocus(); > > if (gTQSender == fDir) > fNameF->SetFocus(); > } > > //----------------------------------------------------------------------// > > void guiex2() > { > new TNewDlog(gClient->GetRoot(), 400, 220); > } > > //-------------------------END------------------- >
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:09 MET