0

I am trying to get the selection that was listed in the qMenu and based on the user selection from the qMenu - camSelBtn, it will display the selection into a qLineEdit - currentCamTxt

However while I am able to get the menu working, the selection is not working.

def camMenu(self):
    allCams = cmds.ls(type='camera', visible = 1)
    camLs = cmds.listRelatives(allCams, p=1)
    menu = QMenu("menu", self.camSelBtn)
    for n in camLs:
        menu.addAction(QAction(n, menu))
    self.camSelBtn.setMenu(menu)

def createConnections(self):
    self.connect(self.setCameraBtn, SIGNAL('clicked()'), self.setCamera)

def setCamera(self):
    for sel in self.camMenu.menu():
        self.currentCamTxt.setText()
dissidia
  • 1,531
  • 3
  • 23
  • 53

2 Answers2

0

Okay, I have managed to find out by adding in a few more stuffs

def camMenu(self):

    # -- Same stuff as I have written

    menu.triggered.connect(self._camSelected)

def _camSelected(self, action):
    self.currentCamTxt.setText(action.text())

Greatly appreciated if there are any better answers than this one :) or, that are coded in a similar fashion as I have posted in my question.

I am still not getting any results if I tried to put in the triggered in the createConenctions

dissidia
  • 1,531
  • 3
  • 23
  • 53
0

The new style signals slots are a lot easier to use.

def camMenu(self):
    menu = QMenu()
    # menu.hovered.connect(lambda name="MainMenu": self.setCamera(name))
    for n in camLs:
        action = QAction(QIcon(), n, None)
        action.hovered.connect(lambda name=n: self.setCamera(name))
        # action.triggered.connect(lambda name=n: self.setCamera(name))

def setCamera(self, name):
    self.currentCamTxt.setText(name)

... if you are just setting the text value then there is no need for the setCamera method.

action.hovered.connect(lambda name=n: self.currentCamTxt.setText(name))
justengel
  • 6,132
  • 4
  • 26
  • 42
  • I tried implementing your code into mine, but when I clicked on the `setCameraBtn`, there are no list of cameras shown – dissidia Oct 02 '14 at 07:28