I have a UI in which it consists of a few QPushButton and a QLineEdit and currently I am having trouble to ‘update’ the contents within this QMenu that was attached onto a QPushButton.
So assumingly, if there are already 2 cameras in my scene, and as I execute my UI, by pressing onto this setCameraBtn I will get the 2 cameras in the list. However, if I create a new camera where the UI is not yet close, how do I make my QMenu to read in the new camera, like a ‘live-update’?
I tried creating another function where it re-read the cameras in scene and retabulate the camLs as well as a connection similar to the one that I have written in the createConnections but it does not seems to be reading in.
camLs = []
class orientCameraUI(QDialog):
def __init__(self, parent=None):
...
...
def initUI(self):
...
...
def createConnections(self):
self.connect(self.orientToCamBtn, SIGNAL('clicked()'), self.orientToCam)
def camMenu(self):
allCams = [cam for cam in cmds.listRelatives(cmds.ls(cameras=1),parent=1) if cam not in ['front','persp','side','top']]
camLs.extend(allCams)
menu = QMenu("menu", self.setCameraBtn)
for item in camLs:
menu.addAction(QAction(item, menu))
self.setCameraBtn.setMenu(menu)
menu.triggered.connect(self._camSelected)
def _camSelected(self, action):
self.currentCamTxt.setText(action.text())