TGListBox and double click

Hello,

I would like to double click on one of the elements of a tglistbox instead of selecting and then clicking on a button. Am I missing something or is it not currently possible ?
There doesn’t seem to be any signal for the double click in TGListBox.

Thanks for any hint,

Barth

Hi Barth,

Try this way:

fListBox->GetContainer()->Connect("DoubleClicked(TGFrame*, Int_t)", "MyMainFrame", this, "HandleContainer(TGFrame*, Int_t)");
And then you can use a slot like this:

void MyMainFrame::HandleContainer(TGFrame *f, Int_t btn) { // HandleContainer slot TGTextLBEntry *entry = (TGTextLBEntry *)f; Printf("Slot HandleContainer(%s, %d)", entry->GetTitle(), btn); }
Cheers, Bertrand.

It works, thanks !

Hi Bertrand,

I come back to this issue because I noticed something strange. When I scroll the TGListBox, I receive DoubleClicked events. Now that I know this behaviour, I will put a check on the button being pressed, but nevertheless it seems weird to me.

What do you think ? is it on purpose ?

I attach a script to reproduce.

Cheer,s
Barth
listBox.C (3.75 KB)

Hi Barth,

The problem is that (at least on Linux) mouse wheel events (scroll up/down) are handled as regular mouse buttons (button 4/5) and then it may generate double-clicks, depending on how your wheel gives clicks…
So yes, you have to properly handle/check which mouse button generates the event.

Cheers, Bertrand.

Hello,
I generate plenty of doubleclicks with mouse wheel.
How do I find which mouse button is responsible for the action please?
jaromir

Hi jaromir,

In this particular case:

fListBox->GetContainer()->Connect("DoubleClicked(TGFrame*, Int_t)", "MyMainFrame", this, "DoubleClicked(TGFrame*, Int_t)"); The secont argument of the “DoubleClicked(TGFrame*, Int_t)” signal is the button number

Cheers, Bertrand.

Dear Bertrand,
thanks for a really fast answer, it compiles fine, but this new function never gets called. My listbox is inside a frame:

TGHorizontalFrame *hBframe = new TGHorizontalFrame(this);

fListBox2 = new TGListBox(hBframe, 101);

I have already a signal from it (in ClickResponse) that works 100%:
fListBox2->Connect(“Selected(Int_t, Int_t)”, “MyMainFrame”, this, “ClickResponse(Int_t, Int_t)”);
I added the line
fListBox2->GetContainer()->Connect(“DoubleClicked(TGFrame*, Int_t)”, “MyMainFrame”,
this, “ClickResponseDC(TGFrame*, Int_t)”);

Nothing happens.

If I look what object the fListBox2->GetContainer() gives ( via ->ClassName() ), I can see that the class is:
TGLBContainer

I tried few more things, removed the previous signal(Selected), hBframe->connect(doesnot compile), but nothing, I am still missing something…
sorry
Jaromir

[quote=“bellenot”]Hi jaromir,

In this particular case:

fListBox->GetContainer()->Connect("DoubleClicked(TGFrame*, Int_t)", "MyMainFrame", this, "DoubleClicked(TGFrame*, Int_t)"); The secont argument of the “DoubleClicked(TGFrame*, Int_t)” signal is the button number

Cheers, Bertrand.[/quote]

Hi jaromir,

Sorry, my mistake, there are now three DoubleClicked signals emitted by TGListBox:

DoubleClicked(Int_t widgetId, Int_t id); //*SIGNAL* DoubleClicked(Int_t id) { Emit("DoubleClicked(Int_t)", id); } //*SIGNAL* DoubleClicked(const char *txt) { Emit("DoubleClicked(char*)", txt); } //*SIGNAL
So now you can connect your mainframe to any of them, e.g.:

fListBox2->Connect("DoubleClicked(Int_t)", "MyMainFrame", this, "ClickResponseDC(Int_t)");
Sorry for the confusion.

Cheers, Bertrand.

Hello Bertrand,
thank you. My problem is that (with my mouse #1) I generate a lot of doubleclicks by a mouse wheel.
With fListBox2->Connect("DoubleClicked(Int_t)", "MyMainFrame", this,...
which I use, I get only a position of an item in the list, not the info on mouse button.
Moreover, I would be happy to have also right click in TGListBox.
Or I do not understand, maybe I should connect some higher level frame and not TGListBox?
Best regards
jaromir

[quote=“bellenot”]Hi jaromir,

Sorry, my mistake, there are now three DoubleClicked signals emitted by TGListBox:

DoubleClicked(Int_t widgetId, Int_t id); //*SIGNAL* DoubleClicked(Int_t id) { Emit("DoubleClicked(Int_t)", id); } //*SIGNAL* DoubleClicked(const char *txt) { Emit("DoubleClicked(char*)", txt); } //*SIGNAL
So now you can connect your mainframe to any of them, e.g.:

fListBox2->Connect("DoubleClicked(Int_t)", "MyMainFrame", this, "ClickResponseDC(Int_t)");
Sorry for the confusion.

Cheers, Bertrand.[/quote]

Hi jaromir,

Oh, OK, I see the problem. Unfortunately, I don’t have a simple solution to this issue right now. I’ll investigate and let you know as soon as possible.

Cheers, Bertrand.

Hi jaromir,

Actually it was simpler than expected and a fix has been submitted in the trunk (r39706) and the v5-30-00-patches branch (r39707). You can now simply connect to the container. For example:

   fListBox->GetContainer()->Connect("DoubleClicked(TGFrame*,Int_t)", "MyMainFrame",
                     this, "DoubleClicked(TGFrame*,Int_t)");
   fListBox->GetContainer()->Connect("ProcessedEvent(Event_t*)", "MyMainFrame", 
                     this, "LBCEvent(Event_t*)");

void MyMainFrame::LBCEvent(Event_t *ev)
{
   if (ev->fType == kButtonRelease) {
      if (ev->fCode == kButton1)
         cout << "Left clicked on entry#" << fListBox->GetSelected() << endl;
      if (ev->fCode == kButton3)
         cout << "Right clicked on entry #" << fListBox->GetSelected() << endl;
   }
}

void MyMainFrame::DoubleClicked(TGFrame *f, Int_t btn)
{
   if (btn < 4) {
      cout << "Double clicked on " << ((TGTextLBEntry *)f)->GetTitle(), 
           << " with button " << btn << endl;
   }
}

Cheers, Bertrand.

Hi,
I suppose I should have installed 5.30 before compiling this (or does it compile with 5.28 ?) . I will install the RC and check it soon. Thank you Bertrand,
best regards
jaromir