前面试过在Qt中实现右击菜单Qt右击菜单 现在尝试在嵌套在Qt中的VTK窗口实现右击菜单 原有方式不能成功。原因也很简单:在VTK窗口发送的是VTKEvent 所以Qt中的
contextMenuEvent(QContextMenuEvent *event) 不会处理该事件。所以要另谋出路 翻阅VTK文档发现了一个实现右击菜单的实例 贴出来与大家分享:
void GUI4::popup(vtkObject * obj, unsigned long,
void * client_data, void *,
vtkCommand * command)
{
// A note about context menus in Qt and the QVTKWidget
// You may find it easy to just do context menus on right button up,
// due to the event proxy mechanism in place.
// That usually works, except in some cases.
// One case is where you capture context menu events that
// child windows don't process. You could end up with a second
// context menu after the first one.
// See QVTKWidget::ContextMenuEvent enum which was added after the
// writing of th