Creating a custom slider for a toolbar


I am trying to create a custom toolbar slider:

      class CustomToolbarSlider : public juce::ToolbarItemComponent, public juce::Slider {
		CustomToolbarSlider(int itemId, const juce::String& labelText, bool asButton) : juce::ToolbarItemComponent(itemId, labelText, asButton) {  };
		bool getToolbarItemSizes(int toolbarThickness, bool isToolbarVertical, int &preferredSize, int &minSize, int &maxSize) override { return false; };
		void paintButtonArea(juce::Graphics &g, int width, int height, bool isMouseOver, bool isMouseDown) override {  };
		void contentAreaChanged(const juce::Rectangle< int > &newBounds) override {  };

	CustomToolbarSlider *frameSlider;

But when I try to setListener or setTooltip:

    (frameSlider = new CustomToolbarSlider(frame_slider, "", 0))->setTooltip("Open image(s) from file(s)");

I get ambiguous access error for both setListener() and setTooltip(). How can I fix this?


Could the slider be a member rather than inheriting from it?


To help the compiler you could try to explicitly cast:

frameSlider = new CustomToolbarSlider(frame_slider, "", 0);
static_cast<ToolBarItemComponent*> (frameSlider)->setToolTip ("Open image(s) from file(s)");
frameSlider->addListener (static_cast<Button::Listener*> (mainGUI));

But I am afraid it only shifts the problems, because you have the so called diamond problem, inheriting twice from the same class, in this case Component. That enables all sorts of strange effects.

Good luck


This sounds like a safer solution…