title: Removing dynamically created Qmenu items
body: <p>I have a Qmenu that I am creating by loading a list with Qsettings and I am trying to be able to remove items from the menu by loading the list in a QListQWidget and deleting the selected items. Currently I am able to delete the menu items in the list widget and it removes them from qsettings as well but I can't figure out how to remove the items from the menu without restarting. I have tried various things such as removeAction etc but haven't been able to figure it out.<br>
  Here is my code:</p>
  
  <pre><code>import functools
  import sys
  from PyQt5 import QtCore
  from PyQt5.QtWidgets import QWidget, QPushButton, QHBoxLayout, \
      QApplication, QAction, QMenu, QListWidgetItem, \
      QListWidget, QGridLayout
  
  class MainWindow(QWidget):
      settings = QtCore.QSettings('test_org', 'my_app')
      def __init__(self, parent=None):
          super(MainWindow, self).__init__(parent)
          self.layout = QHBoxLayout()
          self.menu_btn = QPushButton()
          self.menu = QMenu()
          self.add_menu = self.menu.addMenu("Menu")
          self.menu_btn.setMenu(self.menu)
          self.open_list_btn = QPushButton('open list')
  
          self.load_items = self.settings.value('menu_items', [])
          for item in self.load_items:
              self.action = QAction(item[0], self)
              self.action.setData(item)
              self.add_menu.addAction(self.action)
              self.action.triggered.connect(functools.partial(self.menu_clicked, self.action))
  
          self.layout.addWidget(self.menu_btn)
          self.layout.addWidget(self.open_list_btn)
          self.setLayout(self.layout)
          self.open_list_btn.clicked.connect(self.open_window)
  
      def open_window(self):
          self.create_menu_item = List()
          self.create_menu_item.show()
  
      def menu_clicked(self, item):
          itmData = item.data()
          print(itmData)
  
  class List(QWidget):
      settings = QtCore.QSettings('test_org', 'my_app')
      def __init__(self, parent=None):
          super(List, self).__init__(parent)
          self.menu_items = self.settings.value('menu_items', [])
          self.layout = QGridLayout()
          self.list = QListWidget()
          self.remove_btn = QPushButton('Remove')
          self.layout.addWidget(self.list, 1, 1, 1, 1)
          self.layout.addWidget(self.remove_btn, 2, 1, 1, 1)
          self.setLayout(self.layout)
          self.remove_btn.clicked.connect(self.remove_items)
  
          for item in self.menu_items:
              self.item = QListWidgetItem()
              self.item.setText(str(item[0]))
              self.list.addItem(self.item)
  
      def remove_items(self):
          self.menu_items = self.settings.value('menu_items', [])
          del self.menu_items[self.list.currentRow()]
          self.settings.setValue('menu_items', self.menu_items)
          listItems = self.list.selectedItems()
          if not listItems: return
          for item in listItems:
              self.list.takeItem(self.list.row(item))
  
  if __name__ == '__main__':
      app = QApplication(sys.argv)
      w = MainWindow()
      w.show()
      app.exec_()
  </code></pre>
  
  <p>Does anyone have any ideas?</p>
  
  <p>EDIT:</p>
  
  <p>This is the structure of the list in QSettings. I load the menu with this and I load the QlistWidget with this. I am trying to get the menu to remove the items as well when I remove them for the QListWidget.</p>
  
  <pre><code>mylist = ['item_name',['itemdata1', 'itemdata2', 'itemdata3'], 
            'item_name2',['itemdata1', 'itemdata2', 'itemdata3'], 
            'item_name3',['itemdata1', 'itemdata2', 'itemdata3']]
  </code></pre>