Reputation: 111
So, i'm pretty new in PySide and QT, and want to know how to remove menuitem (it does not matter what kind of (undo, redo, copy, paste and etc)) from QTextEdit standart context menu.
Or tell me a way to get QMenu object of this context menu. Then i can apply removeAction method to menuitem.
TIA.
Upvotes: 2
Views: 2696
Reputation: 120578
To get full control over the context menu, first use QWidget.setContextMenuPolicy to change the context meu policy to Qt.CustomContextMenu
. Then connect a handler to the QWidget.customContextMenuRequested signal. In the handler, you can then get a standard context menu object using the QTextEdit.createStandardContextMenu method.
Modify the menu as you see fit, and then show it using the QPoint
passed to the signal handler like this:
menu.exec_(textedit.viewport().mapToGlobal(point))
Upvotes: 3
Reputation: 92559
Welcome to pyside! :-)
Since QTextEdit inherits QWidget you would probably want to set the context menu policy to custom and then supply you own popup menu
The reason i suggest creating your own custom context is because the qmenu isnt really accessible as a persistant object on the qtextedit. Its build on the fly basd on the context at the moment it was clicked. Im not sure there is a method you can overload to gain acces to the qmenu before it is shown. I think the best you can do is define your own completly.
Upvotes: 2