I want to give my ComboBox a custom LookAndFeel: Whenever the mouse is over the ComboBox, I want to highlight it.
The problem: A ComboBox has a Label inside, which holds the text of the ComboBox. As soon as the mouse touches the label, it is no longer over the ComboBox (even thoug it is still inside the ComboBox). And therefore the highlighting does not work.
void MyAppLookAndFeel::drawComboBox(Graphics& g, int width, int height, bool isButtonDown,
int buttonX, int buttonY, int buttonW, int buttonH, ComboBox& box)
{
if (box.isMouseOver(true))
{
...
}
else
{
...
}
}
Just had the same problem and then found this. Since the ComboBox constructor is explicitly calling
setRepaintsOnMouseActivity (true);
in its constructor, shouldn’t we expect this to “just work”?
If there is no intent to fix this, can the call be removed and maybe a comment be left, so future developers won’t waste their time with something that can’t work?
I came across this because I wanted to have a pointing hand cursor when interacting with ComboBox: setMouseCursor (juce::MouseCursor::StandardCursorType::PointingHandCursor);
But the same issue occurs where the ComboBox's child Label intercepts the mouse clicks / mouse pointer interaction. My solution was to make a custom LookAndFeel and override ComboBox::LookAndFeelMethods::createComboBoxTextBox, and when the Label is created, I set it to not intercept mouse clicks: