ComboBox request


#1

Hi Jules, I'm in need of showing text in a ComboBox that is a "combo" (pun intended) of a section heading and an item, so effectively setText on ComboBox will remove the selected ID since the text will not be one of the listed items.

Two options to make this work I think would be 1) make setText (optionally) not deselect the selected ID, but just change the text in the label, or 2) make label protected so I can make a ComboBox subclass that can handle this (by overriding setText).


#2

Could you do it with a custom label created with LookAndFeel::createComboBoxTextBox() ?


#3

Well, halfway sort of. It works, but problem is that when showing the ComboBox popup, the "checkmark" is set where item value == Label::getText, i.e. nowhere. And Label::getText cannot be overridden... :(


#4

The reason the checkmark is missing in the listbox is because getSelectedId always returns zero, since getText gets the "composite text" from my Label class, and as said Label::getText cannot be overridden.


#5

How about a new method setDisplayedText that just sets the label content and does nothing else?


#6

That is not the problem, problem is that Label::getText gets the label content (composite text) which then of course does not match any of the items in the list box, thus no check mark is shown.

Edit: Real culprit is ComboBox::getSelectedId and the row


    return (item != nullptr && getText() == item->name) ? item->itemId : 0;

getText() == item->name will always return false for my case. Any reason why it isn't like this:

    return (item != nullptr) ? item->itemId : 0;

?

 


#7

IIRC it's done like that so that if someone types in some text which doesn't match any of the items, then it needs to report than none of the items are currently selected.


#8

Ok, but that is what is my "problem". Since I cannot override Label::getText, ComboBox::getSelectedId will always return zero -> no check mark in the ComboBox popup list.

Ah well... how about making Label::getText virtual ? :)

 


#9

Ok, I solved it by creating a Label subclass, which in itself has a child Label. The child label is the one showing the header so that the main label's getText returns correct text for the popup to work as expected.