PopupMenu transparent


I’m not sure if this warrants a feature request, as there may be another way to achieve the same outcome, however…

I am building a plugin on windows. I want to create a transparent PopupMenu. Trying to do this through any kind of LookAndFeel does not work. I suspect because the component itself is set to be opaque. Adding the call to setOpaque(false); here allows a transparent menu:

int PopupMenu::showWithOptionalCallback (const Options& options,
                                         ModalComponentManager::Callback* userCallback,
                                         bool canBeModal)
    std::unique_ptr<ModalComponentManager::Callback> userCallbackDeleter (userCallback);
    std::unique_ptr<PopupMenuCompletionCallback> callback (new PopupMenuCompletionCallback());

    if (auto* window = createWindow (options, &(callback->managerOfChosenCommand)))
        callback->component.reset (window);

        PopupMenuSettings::menuWasHiddenBecauseOfAppChange = false;

        window->setVisible (true); // (must be called before enterModalState on Windows to avoid DropShadower confusion)
        window->enterModalState (false, userCallbackDeleter.release());
        ModalComponentManager::getInstance()->attachCallback (window, callback.release());

        window->toFront (false);  // need to do this after making it modal, or it could
                                  // be stuck behind other comps that are already modal..

        if (userCallback == nullptr && canBeModal)
            return window->runModalLoop();
        ignoreUnused (canBeModal);
        jassert (! (userCallback == nullptr && canBeModal));

    return 0;

Would it be possible to get a call to a popup menu directly for this, eg:

juce::PopupMenu menu;

Or similar?

Thanks for reading!

In my LookAndFeel constructor I call:

setColour(PopupMenu::backgroundColourId, MySlightlyTransparentColour);

I set the default LaF with LookAndFeel::setDefaultLookAndFeel() and it just works, no need for any calls to setOpaque or anything else as PopupMenu is already calling setOpaque if the found backgroundColourId warrants it.

Yes, I went down the rabbit hole tonight and found the same thing. Thanks for sharing that. It just wasn’t super obvious at first that the background colour was triggering the set opaque flag in the window component. When I overwrote the draw background function to not fillAll(), I was expecting it to become transparent. It all makes sense now!

1 Like