Editable TGCombBox how to select value

In my GUI, I have a TGComboBox with two possible values:

Later, I want to change the selected value within the script, using the function Select.

This works fine if the TGComboBox is not editable. However, if I define the constructor editable, then the function Select does not update in the GUI the top value shown. It still shows the predefined value in the constructor.

box = new TGComboBox(frame,"predefinedvalue")
box->AddEntry("predefinedvalue",0);
box->AddEntry("newvalue",1);
box->Select(1);

When I click on the box, the “newvalue” is highlighted in the list, but is not show in the top position (is not visible when unclicking). Is this an expected behaviour? How do I manage to move it to the top, as when I click it normally from the GUI instead of command line?

Hi,

I’m not sure I really understand the “editable” issue, but you can try:

   box = new TGComboBox(frame,"predefinedvalue")
   box->AddEntry("predefinedvalue",0);
   box->AddEntry("newvalue",1);
   box->Select(1);
[...]
   box->GetTextEntry()->SetText(cb->GetSelectedEntry()->GetTitle());
   TGListBox *lb = cb->GetListBox();
   ((TGLBContainer *)lb->GetContainer())->SetVsbPosition(lb->GetSelected());

Cheers, Bertrand.

To be more clear:

fSamplesPerPulseBox = new TGComboBox(fFileFrame, "4096");
fSamplesPerPulseBox->AddEntry("4096",0);
fSamplesPerPulseBox->AddEntry("8192",1);
fSamplesPerPulseBox->Select(1);

See attachment 1.png and 2.png for the result I mention (SP value). The 1st value is selected (highlighed when I display the whole list), but the top visible value is not update.

If I define instead as non-editable, by eliminating the second argument of the constructor:

fSamplesPerPulseBox = new TGComboBox(fFileFrame);
fSamplesPerPulseBox->AddEntry("4096",0);
fSamplesPerPulseBox->AddEntry("8192",1);
fSamplesPerPulseBox->Select(1);

then I get attachment 3.png directly, the correct value is shown on top from the beginning and everything is fine.

If you need it, I can provide you with the macro.






Well, this looks strange…

Yes, please, so I can give it a quick look.

Cheers, Bertrand.

Here my macro. I run it with ROOT6.07/07 and Ubuntu 16.04, with the command

root -l pulse_gui.cpp+(0)

As you see, the value 8192 is internally selected (highlighted), but does not show on top of the combo box.

If I switch in PulseSurfer.cpp to line 106, then it works. So something with the non-editable nature of the combo box messes up?

Thanks for your help.
lightPulseSurfer.tar.gz (791 KB)

Hi,

So the problem has been identified and a fix will be applied in git (master). Thanks for the test case.

Cheers, Bertrand.

Thanks.

Can the fix be also backported to 5.34/36?

Hi,

Sorry, but ROOT 5 is frozen, and only critical bugs are back-ported…

Cheers, Bertrand.