Close Popover

Is there a way to close a popover on the desktop programmatically?
I’m sure there is and that I’m just missing it.

myPopoverReference.Close should do the trick.

Built a sample project because you’re always there to support my projects.
PopoverExample.xojo_binary_project

I have no experience with Popovers but running the Desktop Example there are 2 types: PopoverWindow and PopoverContainer

Putting a button with Self.Close in PopoverWindow works.
Putting a button with Self.Close in PopoverContainer doesn’t work.
screencast2024-05-142PM-05-20-ezgif.com-video-to-gif-converter

2 Likes

I always forget to check for sample projects because they’re not included with the IDE anymore :innocent:

The documentation on popovers is horridly thin.

2 Likes

Changed your example Window2 from DesktopWindow to DesktopContainer and it doesn’t close, same behavior as the video above:
screencast2024-05-142PM-10-01-ezgif.com-video-to-gif-converter

Maybe a bug with PopoverContainers?

It seems that when the control owning the PopOver loses focus the PopOver is dismissed. With the exception of the ‘detached’ PopOver this seems to work - perhaps programmatically shift the focus away from the item that is displaying the PopOver.

:person_shrugging: could definitely be related, Chris will have to comment on his implementation.

1 Like

I guess Chris can use PopupWindow to avoid the problem.

That’s what I’ll do. Thanks, all!

isn’t it funny how much time you can spend on workarounds only to find it’s just a bug and there is a perfectly simple alternate approach!

For Popover Containers, use Self.Window.Close if I remember correctly.

4 Likes

Perfect, that works.

Yeah, part of the API I seriously dislike, but it works. I’ve built a DesktopContainer subclass that, among other things, overrides the Close() method to call Self.Window.Close so I get what I expect.

5 Likes

yeah, I was using a DesktopContainer. I changed the super to a DesktopWindow and life is shiny again.

Thanks everybody!

I didn’t know this one. Thanks.

Hi @Chris_Halford

When it is about Popovers based on ContainerControl, don’t forget that these will behave as a ContainerControl itself wrapped into a Popover type window. That means that, in order to close the Window itself, you need to call MyContainerControl.Window.Close… as you would do with any other ContainerControl: Popovers for Xojo Desktop, Web and iOS – Xojo Programming Blog

1 Like