Hi,

There are a couple different modes on a widget for controlling context
menus.
https://doc.qt.io/qt-5/qt.html#ContextMenuPolicy-enum
The default policy, which you are using in your example, uses the
contextMenuEvent on the widget to create the default menu.
The actions mode is the one that will look at the actions() on the widget
and create a menu from that. So you are adding an action that isn't being
considered. The problem is, if you were to switch to the actions mode then
you wouldn't get any of the default actions if they aren't stored in that
widget actions list. The goal you have is to augment the default actions
menu. In a general case this would be more work because you would need to
subclass the widget, reimplement the contextMenuEvent, and defer a callback
after the menu has been show so that you can look it up and modify it.
Fortunately for QLineEdit we don't have to take that approach, as it
provides a method to create the default context menu instance:
createStandardContextMenu
<https://doc.qt.io/qt-5/qlineedit.html#createStandardContextMenu>

Something like this:

class MyLineEdit(QtWidgets.QLineEdit):
    def contextMenuEvent(self, event):
        menu = self.createStandardContextMenu()
        menu.addAction(...)
        menu.exec_(event.globalPos())

Some answers online suggest you could just
reimplement createStandardContextMenu to return a modified menu.
But createStandardContextMenu is not a virtual method as per the api docs,
so it would only work reliably part of the time, when it is being triggered
from python as opposed to internally via Qt C++

Justin



On Wed, Apr 29, 2020 at 7:49 AM Soham Parmar <soham...@gmail.com> wrote:

> Hi,
> I wanted to add action to my lineEdit rightClick context menu which
> contains(undo, redo, cut, copy, paste, delete, selectAll)
> I just want to add one more action.
>
> I am trying this but its not working.
>
> A_exportCS = QtWidgets.QAction(self.LE_csFilePath)
> A_exportCS.setObjectName("A_exportCS")
> self.LE_shapesToExport.addAction(A_exportCS)
>
>
> What am i doing wrong?
>
> Thanks.
>
> --
> 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_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/d8f30791-89a3-449a-8582-a36cdf309790%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/d8f30791-89a3-449a-8582-a36cdf309790%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA27LZZbVGdTHJD9p%3Du%3DYLPzDD%2BSX16kLuvGnvUDm-HQ%3DQ%40mail.gmail.com.

Reply via email to