Issue
I'm creating a custom context menu for a widget in PySide, and I want to preserve Standard menu options, but I want to put them after custom actions.
Is there a way to add actions to QMenu
and set specific order for them?
Here's my current code:
def buildRightClickMenu(self):
self.textBox.setContextMenuPolicy(Qt.CustomContextMenu)
self.textBox.customContextMenuRequested.connect(self.contextMenuRequested)
self.actionSave = QAction(self)
self.actionSave.setText("Save File")
self.actionSave.triggered.connect(self.saveFile)
self.actionOpen = QAction(self)
self.actionOpen.setText("Open File")
self.actionOpen.triggered.connect(self.openFile)
self.menu = self.textBox.createStandardContextMenu()
self.menu.addSeparator()
self.menu.addAction(self.actionOpen)
As expected, this first creates default menu options, and adds a separator and actionOpen
afterwards. I want to put actionOpen
at the start of the context menu, followed by default actions for the widget.
Solution
It is PySide.QtGui.QWidget.insertAction(before, action)
, in QWidget class.
Answered By - Nix
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.