List menu items in Qpushbutton

112 views
Skip to first unread message

likage

unread,
Aug 18, 2014, 5:55:06 AM8/18/14
to python_in...@googlegroups.com
Hi all, I would like to attach a 'menu' when user left-mouse click onto the QPushButton.
Not sure if there are any things that I am suppose to keep a lookout for when integrating/ using Maya and PyQt stuff...

While I tried my code as follows, it works:
cmds.window()
cams
= cmds.ls(camera = 1, visible =1)
createdCams
= cmds.listRelatives(geos, parent=1)
   
cmds
.popupMenu(button=1)
for cam in createdCams:
 cmds
.menuItem(cam)
 
cmds
.showWindow()



However, as I tried to integrate it into this UI of mine, nothing (no menu list for me to choose from) seems to be happening when I click on the button 'Get current Cam', otherwise I may be getting an error -
# Traceback (most recent call last):
#   File "<maya console>", line 32, in getCamera
# TypeError: Invalid flag 'camera'


from PyQt4.QtCore import *
from PyQt4.QtGui import *
import maya.cmds as cmds
import maya.mel as mel


class orientCameraUI(QDialog):
   
def __init__(self, parent=None):
       
super(orientCameraUI, self).__init__(parent)
       
self.resize(300,225)
       
self.initUI()
       
self.createConnections()

   
def initUI(self):
       
self.setWindowTitle('OrientControl UI')
       
self.getCurrentCamBtn = QPushButton('Get current CAM')
       
       
self.orientToCamBtn = QPushButton('Orient To Cam View')
       
#self.autoTrackBtn = QPushButton('Auto Track')
       
self.currentCamTxt = QLineEdit()
       
        gridLayout
= QGridLayout()
        gridLayout
.addWidget(self.getCurrentCamBtn, 0, 1)
        gridLayout
.addWidget(self.currentCamTxt, 0, 2)
       
self.setLayout(gridLayout)
       
   
def createConnections(self):
       
self.connect(self.getCurrentCamBtn, SIGNAL('clicked()'), self.getCamera)
       
   
def getCamera(self):
        cams
= cmds.ls(camera = 1, visible =1)
        createdCams
= cmds.listRelatives(geos, parent=1)
   
        cmds
.popupMenu(button=1)
       
for cam in createdCams:
            cmds
.menuItem(cam)
       
       
def main():
   
global app
   
global form
    app
= qApp
    form
= orientCameraUI()
    form
.show()
   

if __name__ == '__main__':
    main
()  



Any advices?

Justin Israel

unread,
Aug 18, 2014, 7:27:50 AM8/18/14
to python_in...@googlegroups.com
Specifically regarding that error, you have a typo in your call to cmds.ls() within your getCamera() method. You typed "camera = 1", but it should be "cameras = 1"

Also, you may want to consider either using Qt completely, or the native Maya UI, but not mixing them unless you have some specific reason to do so. You should be able to just create a QMenu.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/508eae5f-632c-4eac-8a73-f5f74acab9b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

likage

unread,
Aug 19, 2014, 6:11:24 AM8/19/14
to python_in...@googlegroups.com
Noticed the mistake on my part, my bad.

Correct me if I am wrong, will the following be the way of how I should add in the QMenu under the initUI function?

self.menu = QMenu()
self.menu.addAction('',self.test)
self.getCurrentCamBtn.setMenu(self.menu)
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages