code: def contextMenuEvent(self, event):
          
          menu = QtWidgets.QMenu(self)
  
          for action in self.actions():
              menu.addAction(action)
  
          openAsMenu = self.createOpenAsMenu(parent=menu)
          menu.insertMenu(self.closeItemAction, openAsMenu)
  
          menu.exec_(event.globalPos())
docs: Creates and executes the context menu for the tree view