TGListBox gui : selection without double click?

Hello,

I have a GUI that include a TGListBox. Everything works great, but I would like to make it easier for me to select entries. Right now I have to double click on them to actually trigger the “Selected(Int_t)” member function for the first time. Then single clicks are enough.

I would like to make it work with keyboards arrow (you can highlight entries with arrows, but it does not actually trigger “Selected(Int_t)”). Is it actually possible ?

edit: clarity

The signal DoubleClicked(char*) and DoubleClicked(Int_t) are emitted when pressing enter on a TGListBox entry

Thanks, but I would like to automatically select the entry once it is highlighted with arrows (or automatically press enter when an arrow is pressed)

Try something like this:

   fListBox->GetContainer()->Connect("CurrentChanged(TGFrame*)", nullptr, nullptr, "CurrentChanged(TGFrame*)");

With:

void CurrentChanged(TGFrame *f)
{
   TGLBContainer *lbc = (TGLBContainer *)gTQSender;
   TGTextLBEntry *lbe = (TGTextLBEntry *)f;
   printf("CurrentChanged() : Id = %d, Text = %s\n", lbe->EntryId(), lbe->GetTitle());
   lbc->Select(lbe->EntryId());
   printf("%d selected\n", lbc->GetListBox()->GetSelected());
}

(up to you to adapt it to your use case)

It works as intended :slight_smile:
I have just a question on the first line of the CurrentChanged function, how does gTQSender is related to the TListBox object ? Is it sort of global variable that point to a “current container” ?

It’s a global pointer to the sender of the signal

Alright good to know. Many thanks !

1 Like

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