Errors? Get any? The btn creation can be anywhere in the window/dialog class. Than you connect its context to the add_menu def' that execute as you press right click.
On Tue, Oct 16, 2018 at 6:09 PM <[email protected]> wrote: > On Tuesday, October 16, 2018 at 8:21:02 PM UTC-4, Michael Boon wrote: > > I think Wexler has basically what you need there. > > All the self.my_btn stuff should be in a function, probably in __init__ > for a simple case. > > > > You might also need > > 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. > > > > On Wednesday, 17 October 2018 08:07:54 UTC+11, Wexler wrote: > > > > Here is an example that might put you in the right track...... please > note, I did not test this snippet > > > > > > > > > > > > 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()) > > > > > > > > > > > > > > > > > > > > > > > > > > On Tuesday, October 16, 2018 at 1:42:33 PM UTC-7, Adam Baker wrote:I’m > looking to create a menu that is shown when you preform a right click on a > button. The photo was an example for the maya.cmds.popupMenu() that I want > to repeat using QT Instead. > > > > > > > > Hope this helps > > > > > > > > - Adam > > I am starting to get a little confused with both replies I was able to > capture to left click using > self.my_btn.clicked.connect(partial(self.call_def_left)) but unable to show > the CustomContextMenu with the right click. > > could you please simplify this for me ? > > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/2aabd3f9-5148-4d62-96f0-6a8459433214%40googlegroups.com > . > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CABnQJrdnLwwuZrMFQb3vVhHh_z1%2BVQKyv0N8YdWWzMO34oa6kQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
