Text for a ShapeButton

I am making buttons that I want to be shaped in a specific way, hence the use of ShapeButton. However, I want there to be text inside these buttons and using the setButtonText function inherited from the Button class is not displaying the text. I can confirm the text is being set as I can debug it with getButtonText(), but the text is not visible.

Is it in the background? Do I need to use a custom LookAndFeel?

Shape buttons don’t support displaying text. Could you use a DrawableButton instead?

I will give that a try. I’m sure I can do it, it’s just that it will be created a little differently. Is there a reason the ShapeButton class does not support displaying text but the setButtonText function can still be called?

Even with the DrawableButton I am unable to see the text.

DrawablePath* d = new DrawablePath();
DrawableButton* d2 = new DrawableButton(“butt”, DrawableButton::ImageFitted);
d2->setImages(d->createCopy(), nullptr, nullptr);
d2->setColour(DrawableButton::ColourIds::textColourOnId, Colours::white);
d2->setColour(DrawableButton::ColourIds::textColourId, Colours::white);

I see the buttons in my application with the correct shape I made with the “filledArc” variable, but no text… I still don’t see why the ShapeButton would be unable to display text, perhaps the reason for both not displaying text is related? After all, they both are inheriting the setButtonText function from the Button class, but I’m at a loss at this point.

You’ll need to use DrawableButton::ButtonStyle::ImageAboveTextLabel or your own LookAndFeel class to render the text over the background.

That works to get the text showing but I was trying to get it in the middle of the button. A workaround I found is to use DrawableText and place it in the middle of the button. This does not upset the clickable area of the button as happened when I put an ordinary Label in the middle of the button. Anyway, thanks for the advice.