Signals with TGListBox

Hi,

I have a TGListBox and I want to connect its signals to a function such that when an entry is selected, it will trigger a function.

I find that I can use the Selected(Int_t) signal such that if I mouse-click on the entry, my function is called.

However, if i use the keyboard arrow keys to move the highlighted selection up and down the list, then my function is not called. I tried using the signal SelectionChanged() but that seemed to make no difference. Is there any signal I can use that I am just not seeing in the documentation?

thanks!

Hi,

There is indeed something missing here… For the time being, you can use something like this:

[code] TGLBContainer lbc = (TGLBContainer )fListBox->GetContainer();
lbc->Connect("KeyPressed(TGFrame
,UInt_t,UInt_t)", “YourClass”, this,
"KeyPressed(TGFrame
,UInt_t,UInt_t)");

[…]

void YourClass::KeyPressed(TGFrame *f, UInt_t, UInt_t)
{
TGTextLBEntry *lbe = (TGTextLBEntry *)f;
printf("\nYourClass::KeyPressed() : Id = %d, Text = %s\n",
lbe->EntryId(), lbe->GetTitle());
}
[/code]
The signal is emitted for the entry on which you press the key.

It should be possible to use this method as well:

TGLBContainer *lbc = (TGLBContainer *)fListBox->GetContainer(); lbc->Connect("CurrentChanged(TGFrame*)", "YourClass", this, "CurrentChanged(TGFrame*)");
But I just realized that the signals were never emitted… :blush: This will be fixed in svn very soon.

Cheers, Bertrand.

Hi,

I implemented your first suggestion, but it doesn’t quite work as expected. I seem to get a pointer to the previous TGTextLBEntry - you can see this in action from the attached macro.

Compile with .L testBox.C+
run
testBox a()

when I use the down arrow to move between entries, I get the previous entry printed to screen.

System OS X 10.6.2, root 5.26/00
testBox.C (3.48 KB)

Hi,

Well, yes, indeed, the “KeyPressed()” signal is emitted when you press a key on the current entry, before moving up or down…
But this method:

TGLBContainer *lbc = (TGLBContainer *)fListBox->GetContainer(); lbc->Connect("CurrentChanged(TGFrame*)", "YourClass", this, "CurrentChanged(TGFrame*)");
Is now available in the trunk of svn.

Cheers, Bertrand.

great thanks!

I’m using root 5.27/02

I’ve the same problem. Now this is the situation

  1. TGListBox->Selected signal is emitted ONLY when you change selected item with mouse
  2. TGLBContainer->CurrentChanged signal is emitted ONLY when you change selected item with keyboard
  3. but the real problem is: when you change selected item with keyboard, fLastActive doesn’t change !!! So TGListBox->GetSelected() and TGLBContainer->GetSelectedEntry() returns index/TGLBEntry of last item selected by mouse.

IMHO there’s a sort of competition between TGLBContainer.fLastActive (changed by mouse selection) and TGContainer.fLastActiveEl (changed by keyboard selection)

Hi,

Some signals are emitted when selecting a list box entry with the mouse and other via the keyboard. As explained before, if you connect to the “CurrentChanged(TGFrame*) signal”, it works:

TGLBContainer *lbc = (TGLBContainer*)fListBox->GetContainer(); lbc->Connect("CurrentChanged(TGFrame*)", "YourClass", this, "CurrentChanged(TGFrame*)");
Anyway, I’ll check for inconsistencies in the code, but fLastActiveEl and fLastActive are probably used in two very specific ways. And if you have any more trouble with this, feel free to post a macro showing what is the exact issue, and I’ll take a look.

Cheers, Bertrand.

[quote=“bellenot”]
Anyway, I’ll check for inconsistencies in the code, but fLastActiveEl and fLastActive are probably used in two very specific ways. And if you have any more trouble with this, feel free to post a macro showing what is the exact issue, and I’ll take a look.[/quote]

Ok,
I have a simple macro for you.
Try to change selected item by mouse and by keyboard.

Paolo (yawn)
test.C (1.01 KB)

Hi Paolo,

OK, I see. This is now fixed in svn trunk (revision 33569). Many thanks for the report and for the test macro.

Cheers, Bertrand.