Give focus to TGInputDialog

Hi,

this is probably a trvial question, but I’d like to know how to set the focus to a TGInputDialog. When running the routine (normal ROOT macro, not in context of a TApplication or so)

TStr GetText(TStr prompt="")
{
  char ret[100];
  TGInputDialog *dlg = new TGInputDialog(gClient->GetRoot(), nullptr, prompt.Data(), "", ret);
  TStr txt(ret);
  return txt;
}

I still need to click inside the text field to start typing. Is there a way to set the focus automatically to the TGTextEntry? Or is there even a better way to request user input in a “normal” non-GUI ROOT macro?

Best regards and thanks,
Klaus


ROOT Version: 6.36
Platform: Debian Linux 12
Compiler: Not Provided


No, this is a modal dialog, so you can’t

you mean something like std::cin >> txt;?

Note that you can use the dialogs from macros/Dialogs.C and add a line to set the focus on the text input, like for example:

InputDialog::InputDialog(const char *prompt, const char *defval, char *retstr)
{
   [...]
   // popup dialog and wait till user replies
   fDialog->MapWindow();
   // set the focus to the text input
   gVirtualX->SetInputFocus(fTE->GetId());

   [...]

Of course I tried cin, but inside a routine connected to TExec, I strangely don’t get an echo of the entered text, which is pretty annoying.

Probably you know as well how to solve this issue? :wink:

Well, I’d have to try, or ask @couet
And did you try to use InputDialog(prompt.Data(), "") from macros/Dialogs.C?