Macos – Programmatically controlling a Cocoa Button on OSX (making it invisible and pressed)

cocoamacosnspopupbutton

I am trying to interface with a cocoa popup menu from an OpenGL button. The actual button needs to be in OpenGL and I cannot stick an actual Cocoa button in its place but when this button is pressed I would like for a Cocoa menu to popup just like the one that comes up when you press the nspopupbutton. It seems that there is no way to get this popup window to come up by itself so I wanted to just insert an invisible button and have it be pressed automatically when the popup menu method is called. Is there a way to programmatically set a button to pressed (this will bring up the menu from the popupbutton) and make the button itself invisible without making the resulting menu invisible?

Best Answer

It seems that there is no way to get this popup window to come up by itself

Sure there is. See + popUpContextMenu:withEvent:forView:

Related Topic