Programatically close TContextMenu

Is there a way to programmatically close a context menu (TContextMenu)?
The menu was open by right clicking on the canvas.

Thank you!

I don’t think so, I’ll have to investigate. But what are you trying to do exactly?

In principle, something like this should work:

void *ud;
TContextMenu *cm = fCanvas->GetContextMenu();
if (cm)
   ((TGPopupMenu *)cm->GetContextMenuImp())->EndMenu(ud);

Hello Bertrand!

This approach does not work for me.

  1. TContextMenu *cm = fCanvas->GetContextMenu() returns non-zero cm even if the menu is not shown.
  2. After the menu is shown, and I run your procedure, the menu still remains visible.
  3. next time mouse right-clicked on the canvas (shoud show the menu again), it leads to a crash:
    #5 0x00007f4832550691 in non-virtual thunk to TRootContextMenu::DisplayPopup(int, int) ()
    #6 0x00007f4862abb2aa in TCanvas::HandleInput(EEventType, int, int) ()

On the question “why”:
I have TCanvas shown in a Qt window. I handle mouse actions using the HandleInput method of TCanvas. On right-click, the context menu is shown. However, the only way to close it when it was shown non-intentionally is to click on its title. I would like to find a way to close it programmatically on the mouse click outside the menu.

Thanks again,
Andrey

OK, then I’m afraid there is no solution to your issue…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.