TGListBox - can it connect?

Hi,
I am fighting a bit with gui and (based on an example) I can have TGListBox with a button and on the button press I can read what is selected in the list.
But I would love to connect the listbox to some slot and react on a doublecklick in the listbox. Is it possible?

i tried

// fListBox->Connect(“Clicked()”, “MyMainFrame”, this, “PrintSelected()”);
// fListBox->Connect(“Pressed()”, “MyMainFrame”, this, “PrintSelected()”);

// fListBox->Connect(“Selected()”, “MyMainFrame”, this, “PrintSelected()”);

.

thanks
jaromir

I would try something like that

root.cern.ch/root/html/TGListBox … x:Selected

btw, you need exactly a “doublecklick” event?

it would be much better then a sigleclick, however even singleclick would be fine.

I tried the example - I admit, that I may be missing something - but it doesnot work.

Here is what I added - the last line


public:
   MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
   virtual ~MyMainFrame();
   void DoExit();
   void DoSelect();
   void HandleButtons();
   void PrintSelected();
  void PrintSelected(Int_t w, Int_t i);

then


  fListBox->Connect("Selected(Int_t, Int_t)", "MyMainFrame", this, "PrintSelected(Int_t, Int_t)");

and then the definition - I expect whatever printout

  void  MyMainFrame::PrintSelected(Int_t w, Int_t i);
{
   printf("HandleButton2:  %d\n", 0);
}

something wrong with it?
thanks

[quote=“jaromrax”]

[code]
void MyMainFrame::PrintSelected(Int_t w, Int_t i);
{
printf(“HandleButton2: %d\n”, 0);
}

[/code][/quote]

try this:

  void  MyMainFrame::PrintSelected(Int_t w, Int_t i)
{
   printf("HandleButton2:  %d\n", 0);
}

note semicolon in your example

Hi Jaromir,

Please find attached the example $ROOTSYS/tutorials/gui/listBox.C slightly modified to work in a way described by you, but based on a single mouse click. If you have a single list box in your application you may not need to connect to the signal Selected(Int_t widgetId, Int_t id), which gives you information about widget Id and the selected entry from it. In the provided example I made a connection to the Selected(Int_t id), which gives the selected entry id.

In addition, the lineprintf("HandleButton2: %d\n", 0); from your example above will print the selected entry if you replace 0 by i:printf("HandleButton2: %d\n", i); Cheers, Ilka
listBox.C (3.52 KB)

Great, thank you.
j.

[quote=“anar”][quote=“jaromrax”]

[code]
void MyMainFrame::PrintSelected(Int_t w, Int_t i);
{
printf(“HandleButton2: %d\n”, 0);
}

[/code][/quote]

try this:

  void  MyMainFrame::PrintSelected(Int_t w, Int_t i)
{
   printf("HandleButton2:  %d\n", 0);
}

note semicolon in your example[/quote]