Hey, 
so i have solved the problem,
one more line edit was getting created on the top of existing one,

I want to ask can we change the order of contextMenu? my QAction is getting 
created on bottom, i want to keep it on top.

and i had one more question is i want to create context menu on leftClick 
on pushButton, same as menuButton in menu bar but on QPushButton. how can 
we do that?

On Wednesday, April 29, 2020 at 7:16:27 PM UTC+5:30, Soham Parmar wrote:
>
> Hi,
> that solution perfectly worked as i wanted. 
> but it's making 2 parts of line edit, on first part it's working fine and 
> on second part, i can't write and no context menu.
> I have attached photo that help to understand whats happening.
>
> this is the code
>
> class controlShapes(controlShapesUI.Ui_controlShapes, QtWidgets.QWidget):
>    def __init__(self, parentWin=getMayaWindow()):
>       super(controlShapes, self).__init__(parentWin)
>       self.setupUi(self)
>       
>       self.LE_csFilePath.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
>       customContextMenu(self.LE_csFilePath)
>
> class customContextMenu(QtWidgets.QLineEdit):
>    def contextMenuEvent(self, event):
>       menu = self.createStandardContextMenu()
>       menu.addAction("Export")
>       menu.exec_(event.globalPos())
>
>
> Thanks,
> Soham.
>
> On Wednesday, April 29, 2020 at 2:23:34 AM UTC+5:30, Justin Israel wrote:
>>
>> 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 <soha...@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/b5ab5083-87d3-4d61-8101-37f25609ac38%40googlegroups.com.

Reply via email to