from PyQt4.QtGui import *
from PyQt4.QtCore import *

class Window(QDialog):
    def __init__(self, parent=None):
        super(Window, self).__init__(parent)

        self.vl = QVBoxLayout()
        self.btn = QPushButton()
        self.vl.addWidget(self.btn)
        self.setLayout(self.vl)

        self.btn.setContextMenuPolicy(Qt.CustomContextMenu)
        self.btn.customContextMenuRequested.connect(self.doIt)

        self.popupmenu = QMenu(self)
        self.popupmenu.addAction(QAction('lol', self))

    def doIt(self, point):
        self.popupmenu.exec_(self.btn.mapToGlobal(point))
        print 'lol'


x = Window()
x.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

Reply via email to