I’m trying to develop a Slicer module in which right clicking within a 2d slice view will generate a popup menu.
I’m implementing this functionality in DisplayableManager. I haven’t found a VTK object that implements a popup menu. Instead, I’ve created a DisplayableManagerMenu QOBJECT that has some slots that can be called from a QMenu object.
To get this to compile required changing the CMakeLists.txt file to build the MRMLDM library using SlicerMacroBuildModuleWidgets instead of SlicerMacroBuildModuleLogic, so that I can specifiy the DisplayableManagerMenu as an MOC source.
This actually worked, UNTIL I rebuilt the extension from scratch (ie, removed the entirety of the build directory and recompiled). Then I started getting the following error:
“vtkMRMLSliceViewDisplayableManagerFactory (0x55e643f3d890): RegisterDisplayableManager - Test1DisplayableManager is not a displayable manager. Failed to register”
Interestingly, it works just fine when I initially switch from SlicerMacroBuildModuleLogic to SlicerMacroBuildModuleWidgets if I don’t rebuild from scratch in between. Looking into how these two SlicerMacroBuildModule* functions work, they eventually call SlicerMacroBuildVTKLibrary and SlicerMacroBuildQtLibrary respectively. I get the sense that what I’m trying to do runs contrary to some deep limitation or assumption, since what I seem to need would be a function called “SlicerMacroBuildVTKandQtLibrary”.
I have also tried adding the relevant QT5_WRAP_CPP into a CMakeLists.txt that uses SlicerMacroBuildModuleLogic, but run into problems when Python tries to wrap the moc_DisplayableManagerMenu.h file since that doesn’t exist. Disabling python wrapping generates the same error as above.
Does anyone have any suggestions about:
What SlicerMacroBuildModuleLogic is doing that gets the DisplayableManager registered correctly that isn’t done by SlicerMacroBuildModuleWidgets?
Whether there is a VTK-based alternative to QMenu for generating popup menus?
Any example extensions that implement something similar to this?