You are making a simple dialog that only contains a pushbutton that is added to a vertical layout. You set the context menu option to use a custom menu instead of performing its own default action. And you connect a signal that is emitted when your right click the button to a custom slot that creates a popup menu and shows it. Was there a specific area of the code you wanted more details about?
On Dec 6, 2011, at 9:13 PM, notanymike <[email protected]> wrote: > I found a couple of tutorials and merged them and that seemed to work, > though I still don't know how its working. Could anyone care to > explain: > > import sip > import maya.cmds as cmds > import maya.OpenMayaUI as mui > from PyQt4.QtCore import * > from PyQt4.QtGui import * > > def getMayaWindow(): > ptr = mui.MQtUtil.mainWindow() > return sip.wrapinstance(long(ptr), QObject) > > class Form(QDialog): > > > def __init__(self, parent=None): > super(Form, self).__init__(parent) > self.setObjectName('mainUI') > self.mainLayout = QVBoxLayout(self) > self.myButton = QPushButton('myButton') > self.myButton.setContextMenuPolicy(Qt.CustomContextMenu) > self.myButton.customContextMenuRequested.connect(self.popup) > self.myButton.clicked.connect(self.selectJoint) > self.mainLayout.addWidget(self.myButton) > > def popup(self, pos): > #for i in self.tv.selectionModel().selection().indexes(): > # print i.row(), i.column() > menu = QMenu() > jointAction = menu.addAction("This is an action") > action = menu.exec_(self.mapToGlobal(pos)) > if action == jointAction: > self.myjoint = cmds.joint() > > def selectJoint(self): > cmds.select(self.myjoint) > > global app > global form > app = qApp > form = Form(getMayaWindow()) > form.show() > > > > > On Dec 2, 1:57 pm, Justin Israel <[email protected]> wrote: >> Though this approach would make it a Menu button, activated from a normal >> left click. >> >> On Fri, Dec 2, 2011 at 1:53 PM, David Moulder >> <[email protected]>wrote: >> >> >> >> >> >> >> >>> Alternatively you could try >> >>> 1. QMenu <http://doc.qt.nokia.com/latest/qmenu.html> *menu = new >>> QMenu<http://doc.qt.nokia.com/latest/qmenu.html> >>> (this); >>> 2. menu->addAction("Testaaaaaaaaaaaaaaaaaaaaa"); >>> 3. menu->addAction("Test1"); >>> 4. menu->addAction("Test2"); >>> 5. >>> 6. pushButton->setMenu(menu); >> >>> On Fri, Dec 2, 2011 at 9:47 PM, David Moulder >>> <[email protected]>wrote: >> >>>> I'm not at python console to test this but from memory you need to set >>>> the contextMenu property and then hook up the signal to slot to show your >>>> menu. >> >>>> Qt::ContextMenuPolicy<http://doc.qt.nokia.com/latest/qt.html#ContextMenuPolicy-enum> >> >>>> and >> >>>> >>>> customContextMenuRequested<http://doc.qt.nokia.com/latest/qwidget.html#customContextMenuRequested> >> >>>> Good luck. >> >>>> -Dave >> >>>> On Fri, Dec 2, 2011 at 9:13 PM, notanymike <[email protected]> wrote: >> >>>>> How can one make a drop-down command menu appear when right-clicking >>>>> on a button in a Maya window using pyqt? >> >>>>> -- >>>>> view archives:http://groups.google.com/group/python_inside_maya >>>>> change your subscription settings: >>>>> http://groups.google.com/group/python_inside_maya/subscribe >> >>>> -- >>>> David Moulder >>>> http://www.google.com/profiles/squish3d >> >>> -- >>> David Moulder >>> http://www.google.com/profiles/squish3d >> >>> -- >>> view archives:http://groups.google.com/group/python_inside_maya >>> change your subscription settings: >>> http://groups.google.com/group/python_inside_maya/subscribe > > -- > view archives: http://groups.google.com/group/python_inside_maya > change your subscription settings: > http://groups.google.com/group/python_inside_maya/subscribe -- view archives: http://groups.google.com/group/python_inside_maya change your subscription settings: http://groups.google.com/group/python_inside_maya/subscribe
