Bool isLabelWithinComboBox


#1

Would it be possible to have a bool method for Label that returns true if the label is within a ComboBox?

Thank you.


#2

Why would you need that…? You could just use e.g. Component::findParentComponentOfClass to see if it’s inside a ComboBox, right?


#3

Indeed, I’ve got

if (dynamic_cast <ComboBox*> (label.getParentComponent()) == nullptr)

working, it just seemed a little long, and requiring a cast. I guess when you think a method is obvious you just expect it to be there!


#4

If I were you I’d use findParentComponentOfClass instead - you’re making an assumption there that the Label is a direct child of the ComboBox, which may not always be the case.


#5

Even better, thank you!