How can I override ComboBox getToolTip()?


#1

I’m trying to override ComboBox::getTooltip() so that it displays the current item name. I’m finding that I can override Slider::getTooltip() without a problem, but ComboBox::getTooltip(), ignores my override.

// Works

class MySlider : public Slider
{
public:
    MySlider (const String& name) : Slider (name) {};
    ~MySlider () {};
        
    String getTooltip () override
    {
        return getTextFromValue (Slider::getValue ());
    }
};

// Doesn’t work

class MyComboBox : public ComboBox
{
public:
    MyComboBox (const String& name) : ComboBox (name) {};
    ~MyComboBox () {};

    String getTooltip () override
    {
        return ComboBox::getText ();
    }
};

Could someone tell me how to get this to work?


#2

My guess is that your code partially works : you will probably only have the tooltip you want when you hover the combobox arrow.
That’s because the combobox contains a label, so when you hover the combobox, it’s actually the label’s tooltip that is used.
Perhaps you can simply set the tooltip using setTooltip?

    struct MyComboBox : public ComboBox
    {
        MyComboBox()
        {
            onChange = [this]() { setTooltip (getText()); };
        }
    };

you could also create a customized label in your lookandFeel::createComboBoxTextBox() method