I have created a context menu.

+Main 1 > Sub 1.1 > Sub 1.1.1
+Main 1 > Sub 1.1 > Sub 1.1.2
+Main 2

The context menu is going to be shown by a click on a list.
The problem is, when I clicked near the border of mainscreen, some part of the sub-menus' stays outside the screen.
To solve this issue, I tried to show sub-menus in a moved position but I have failed.
It moved but crashed the software...

Here is my creater method:
Qt Code:
  1. def rightClickMenu_create(self):
  2. self.context_menu = QMenu(self)
  3.  
  4. self.item1 = self.context_menu.addMenu("Main 1")
  5. item2 = self.context_menu.addAction("Main 2")
  6.  
  7. self.item1_1 = self.item1.addMenu("Sub 1.1")
  8. self.item1_1.addAction("Sub-sub 1.1.1")
  9. self.item1_1.addAction("Sub-sub 1.1.2")
  10.  
  11. self.item1.aboutToShow.connect(self.show_sub_menu_at_position)
To copy to clipboard, switch view to plain text mode 

I can show the menu with;
Qt Code:
  1. def show_main_menu(self):
  2. self.context_menu.exec_(QCursor.pos())
To copy to clipboard, switch view to plain text mode 


I want to move the sub-menu with;
Qt Code:
  1. def show_sub_menu_at_position(self):
  2. self.item1.aboutToShow.disconnect(self.show_sub_menu_at_position)
  3. self.item1.exec_(self.mapToGlobal(QPoint(50, 50)))
To copy to clipboard, switch view to plain text mode 

Also tried this;

Qt Code:
  1. def show_sub_menu_at_position(self):
  2. if sistem.isContextShown == 0:
  3. sistem.isContextShown = 1
  4. self.item1.exec_(self.mapToGlobal(QPoint(50, 50)))
To copy to clipboard, switch view to plain text mode 
How can I move the sub-menu to another coordinate or how to keep my context-menu inside the borders?

If the menu opened on the right side of the main window, the sub-menus must be opened to right, if on the left border must be opened to right, if on top must open to bottom, if on bottom must be opened to top....