Customized value box next to slider

Hi all,

I’ve made my own class, subclassed from juce::Slider,
and I overrode the paint(…) method to draw a unique slider design with a custom bar and knob for my new slider class, which works nicely.

However, the rectangular white box with the value as text inside it, which is part of the slider, doesn’t seem to be drawn by the paint() methods as it always stays there and looks the same…

I don’t just have to change the colours of this box and the text inside,
but want to draw a custom one myself from scratch with the graphics commands…

Can someone explain how to do this, in an easy fashion ? (eg if you could explain the easiest way, and with an example or so…)

Thanks for your time, much appreciated :slight_smile:

I am no great shakes as a JUCE programmer but I believe any reply you get will recommend that you do not touch the paint() method but rather create your own LookAndFeel Class with its own drawLinearSlider() method. Take a look at the existing methods such as LookAndFeel_V2::drawLinearSlider() to get some ideas as to how to go about that.

The value box is actually a Label which lives inside the Slider which you have very limited access to. (There are some other threads on this which you can find by searching for Slider and valueBox)

It may be helpful to have your custom slider not show a text box, then make a separate TextSlider widget (based off of Slider’s vertical drag bar slider where you just don’t paint the bar) which only contains the text field. Both of them can attach to the same parameter for the APVTS and it gives you greater flexibility WRT layout. (For example, if you want to display the value in the center of a dial, there’s no way to do this with the existing Slider) TextSlider is the type of widget that ends up being pretty handy to have around, since you can stick it on dials or sliders or use it on its own.

You can then use composition to make a component that contains the dial/slide, textslider, and label with layout happening automatically.

As mentioned, it is a Label. Override drawLabel() in the LookAndFeel applied to the sliders. Use a separate LookAndFeel for your sliders so it doesn’t affect other labels.

Hi guys,

Thanks for all your replies, now I know what to do :slight_smile:
If I run into any more issues, I’ll reply here, but I think I understand it now,
I’m just going to stop using classes and overriding the paint methods and use the lookandfeel system instead…


1 Like