title: How to interactively add widgets using QAction in Pyside/Pyqt without using layout management?
body: <p>I'm trying to make a tool window for Maya, in which I can right-click anywhere, and if I click 'add', a rectangle widget shows up at my cursor position.</p>
  
  <p>Now my right-click functionality works. I can also get my cursor position in <code>addPicker()</code> function. But I am having problem with placing newly-created widgets. If I add a layout and add the newly-created widgets to it, they actually show up. However, if I didn't create a layout for those widgets, no matter what position I tested, nothing shows up in my window.</p>
  
  <p>Hopefully someone has some ideas. Thank you all in advance.</p>
  
  <p>A right-click screenshot:
  <a href="https://i.stack.imgur.com/Ixh2M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ixh2M.png" alt="A right-click screenshot"></a></p>
  
  <pre><code>class RightClickMenu(QtGui.QMenu):
  
      def __init__(self, *args, **kwargs):
          super(RightClickMenu, self).__init__(*args)
  
          self.parentWidget().setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
          self.parentWidget().customContextMenuRequested.connect(self.menuPos)
  
      def menuPos(self, *args):
          self.exec_(QtGui.QCursor.pos())
  
  class Ui_window(object):
      def setupUi(self, window):
          window.setObjectName("window")
          window.resize(555, 900)
          self.widget_base = QtGui.QWidget()
  
          self.verticalLayout_window = QtGui.QVBoxLayout(window)
          self.verticalLayout_window.addWidget(self.widget_base)
  
          self.menu_popup = RightClickMenu(self.widget_base)
          self.menu_popup.setObjectName("popupMenu")
          self.verticalLayout_widget = QtGui.QVBoxLayout(self.widget_base)
  
          # Action - add picker
          addAction = QtGui.QAction('Add Picker', self.widget_base)
          addAction.setShortcut('Ctrl+A')
          addAction.setStatusTip('Add Picker')
          addAction.triggered.connect(self.addPicker)
          self.menu_popup.addAction(addAction)
  
          # Action - delete picker
          deleteAction = QtGui.QAction('Delete Picker', self.widget_base)
          deleteAction.setShortcut('Ctrl+D')
          deleteAction.setStatusTip('Delete Picker')
          deleteAction.triggered.connect(self.deletePicker)
          self.menu_popup.addAction(deleteAction)
  
      def addPicker(self):
          cursorPos = QtGui.QCursor.pos()
          localPos = self.widget_base.mapFromGlobal(cursorPos)
  ######################################################################
          # how??? below doesn't work.
          self.pushButton = QtGui.QPushButton(self.widget_base)
          self.pushButton.setGeometry(QtCore.QRect(220, 50, 75, 23))
          self.pushButton.setObjectName("pushButton")
  
      def deletePicker(self):
          print 'delete'
  
  
  
  def run():
      import sys
      try:
          Ui_window.close()
      except:
          pass
  
      pickerWindow = QtGui.QDialog()
      ui = Ui_window()
      ui.setupUi(pickerWindow)
      pickerWindow.show()
      pickerWindow.exec_()
  </code></pre>