and then write your own showCustomContextMenu(self, point) function that creates a QMenu and assigns QActions to it, then shows the menu using something like
self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.showCustomContextMenu)
menu.popup(self.mapToGlobal(point))
Hope this helps, as I am a little confused on how to implement what you are saying.
- Adam B.
--
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/04963cac-2347-4ef3-bbc3-8b321864881b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
from functools import partial
class MyUI(window or dialog or widget or whatever...):
# create a button
self.my_btn = QtWidgets.QPushButton('Right Click Me')
# left click
self.my_btn.clicked.connect(partial(self.call_def_left))
# set it with custom menu Contex
self.my_btn.customContextMenuRequested.connect(partial(self.add_menu))
# menu thingy, this is the right click
def add_menu(self):
""" add menus to btns """
menu = QtWidgets.QMenu(self)
for char_env in [('Char Yes', QtGui.QPixmap('img_char_location')),
('Env Yes', QtGui.QPixmap('img_env_location'))
]:
action = QtWidgets.QAction(char_env[1], char_env[0], self,
triggered=partial(self.call_def_YES))
# add the action to the menu
menu.addAction(action)
# exec' the menu on the position of the cursor
menu.exec_(QtGui.QCursor.pos())
self.my_btn.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
and the connections don't need to use a partial function as long as you accept the correct arguments in your connected functions.
--
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/2aabd3f9-5148-4d62-96f0-6a8459433214%40googlegroups.com.
Thanks
- Adam B.
--
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/2aabd3f9-5148-4d62-96f0-6a8459433214%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4c3d1f67-564d-4068-8868-747e3b46bb53%40googlegroups.com.