Python PyQt5.QtGui.QContextMenuEvent() Examples

The following are 16 code examples for showing how to use PyQt5.QtGui.QContextMenuEvent(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module PyQt5.QtGui , or try the search function .

Example 1
Project: track   Author: frans-fuerst   File: mainwindow.py    License: Apache License 2.0 7 votes vote down vote up
def event(self, e):
        if not isinstance(e, (
                QtCore.QEvent,
                QtCore.QChildEvent,
                QtCore.QDynamicPropertyChangeEvent,
                QtGui.QPaintEvent,
                QtGui.QHoverEvent,
                QtGui.QMoveEvent,
                QtGui.QEnterEvent,
                QtGui.QResizeEvent,
                QtGui.QShowEvent,
                QtGui.QPlatformSurfaceEvent,
                QtGui.QWindowStateChangeEvent,
                QtGui.QKeyEvent,
                QtGui.QWheelEvent,
                QtGui.QMouseEvent,
                QtGui.QFocusEvent,
                QtGui.QHelpEvent,
                QtGui.QHideEvent,
                QtGui.QCloseEvent,
                QtGui.QInputMethodQueryEvent,
                QtGui.QContextMenuEvent,
                )):
            log().warning("unknown event: %r %r", e.type(), e)
        return super().event(e) 
Example 2
Project: hase   Author: hase-project   File: viewtable.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def contextMenuEvent(self, event: QContextMenuEvent) -> None:
        col = self.columnAt(event.pos().x())
        row = self.rowAt(event.pos().y())
        if col == 3:
            item = self.item(row, col)
            vtype = item.value_type
            if vtype != "unknown":
                menu = QMenu(self)
                as_int = QAction("repr as int", self)
                as_int.triggered.connect(lambda: self.repr_as_int(row, col))
                as_hex = QAction("repr as hex", self)
                as_hex.triggered.connect(lambda: self.repr_as_hex(row, col))
                as_flt = QAction("repr as floating", self)
                as_flt.triggered.connect(lambda: self.repr_as_floating(row, col))
                as_str = QAction("repr as str", self)
                as_str.triggered.connect(lambda: self.repr_as_str(row, col))
                as_bys = QAction("repr as bytes", self)
                as_bys.triggered.connect(lambda: self.repr_as_bytes(row, col))
                menu.addAction(as_int)
                menu.addAction(as_hex)
                menu.addAction(as_flt)
                menu.addAction(as_str)
                menu.addAction(as_bys)
                menu.popup(QCursor.pos()) 
Example 3
Project: uPyLoader   Author: BetaRavener   File: transfer_tree_view.py    License: MIT License 5 votes vote down vote up
def contextMenuEvent(self, *args, **kwargs):
        ev = args[0]
        assert isinstance(ev, QContextMenuEvent)

        point = ev.pos()
        rows = self.selectionModel().selectedRows()
        self._destination_menu_action.setEnabled(False)

        if rows:
            if len(rows) == 1 and self.model().isDir(rows[0]):
                self._destination_menu_action.setEnabled(True)

            self.context_menu.exec(self.mapToGlobal(point)) 
Example 4
Project: CvStudio   Author: haruiz   File: labels_tableview.py    License: MIT License 5 votes vote down vote up
def contextMenuEvent(self, evt: QContextMenuEvent) -> None:
        menu = QMenu()
        menu.triggered.connect(self.context_menu_actions_handler)
        index: QModelIndex = self.indexAt(evt.pos())
        if index.isValid():
            icon: QIcon = GUIUtilities.get_icon('delete_label.png')
            action = menu.addAction(icon, self.CTX_MENU_DELETE_LABEL)
            action.setData(index)
        else:
            icon: QIcon = GUIUtilities.get_icon('new_label.png')
            menu.addAction(icon, self.CTX_MENU_ADD_LABEL)
        menu.exec_(self.mapToGlobal(evt.pos())) 
Example 5
Project: CvStudio   Author: haruiz   File: models_treeview.py    License: MIT License 5 votes vote down vote up
def contextMenuEvent(self, evt: QContextMenuEvent) -> None:
        index: QModelIndex = self.indexAt(evt.pos())
        actions = []
        if index.isValid():
            node: CustomNode = index.internalPointer()
            index: QModelIndex = self.indexAt(evt.pos())
            menu = QMenu()
            menu.triggered.connect(self.context_menu_actions_handler)
            if node.level == 1:
                actions = [
                    QAction(gui.get_icon('new_folder.png'), self.CTX_MENU_ADD_REPOSITORY_ACTION)
                ]
            elif node.level == 2:
                actions = [
                    QAction(gui.get_icon('delete.png'), self.CTX_MENU_DELETE_REPO_ACTION),
                    QAction(gui.get_icon('refresh.png'), self.CTX_MENU_UPDATE_REPO_ACTION)
                ]
            elif node.level == 3:
                actions = [
                    QAction(gui.get_icon('robotic-hand.png'), self.CTX_MENU_AUTO_LABEL_ACTION)
                ]
            if actions:
                for act in actions:
                    act.setData(index)
                    menu.addAction(act)
            menu.exec_(self.mapToGlobal(evt.pos())) 
Example 6
Project: urh   Author: jopohl   File: CompareFrameController.py    License: GNU General Public License v3.0 5 votes vote down vote up
def contextMenuEvent(self, event: QContextMenuEvent):
        pass 
Example 7
Project: urh   Author: jopohl   File: ProtocolTreeView.py    License: GNU General Public License v3.0 5 votes vote down vote up
def contextMenuEvent(self, event: QContextMenuEvent):
        self.context_menu_pos = event.pos()
        menu = self.create_context_menu()
        menu.exec(self.mapToGlobal(event.pos()))
        self.context_menu_pos = None 
Example 8
Project: urh   Author: jopohl   File: ParticipantTableView.py    License: GNU General Public License v3.0 5 votes vote down vote up
def contextMenuEvent(self, event: QContextMenuEvent):
        self.create_context_menu().exec_(self.mapToGlobal(event.pos())) 
Example 9
Project: urh   Author: jopohl   File: MessageTypeTableView.py    License: GNU General Public License v3.0 5 votes vote down vote up
def contextMenuEvent(self, event: QContextMenuEvent):
        self.create_context_menu().exec_(self.mapToGlobal(event.pos())) 
Example 10
Project: urh   Author: jopohl   File: TextEditProtocolView.py    License: GNU General Public License v3.0 5 votes vote down vote up
def contextMenuEvent(self, event: QContextMenuEvent):
        menu = self.create_context_menu()
        menu.exec_(self.mapToGlobal(event.pos())) 
Example 11
Project: urh   Author: jopohl   File: GeneratorListView.py    License: GNU General Public License v3.0 5 votes vote down vote up
def contextMenuEvent(self, event: QContextMenuEvent):
        self.context_menu_pos = event.pos()
        menu = self.create_context_menu()
        menu.exec(self.mapToGlobal(self.context_menu_pos))
        self.context_menu_pos = None 
Example 12
Project: urh   Author: jopohl   File: DirectoryTreeView.py    License: GNU General Public License v3.0 5 votes vote down vote up
def contextMenuEvent(self, event: QContextMenuEvent):
        menu = self.create_context_menu()
        menu.exec_(self.mapToGlobal(event.pos())) 
Example 13
Project: urh   Author: jopohl   File: LabelValueTableView.py    License: GNU General Public License v3.0 5 votes vote down vote up
def contextMenuEvent(self, event: QContextMenuEvent):
        menu = self.create_context_menu()
        menu.exec_(self.mapToGlobal(event.pos())) 
Example 14
Project: urh   Author: jopohl   File: ZoomableGraphicView.py    License: GNU General Public License v3.0 5 votes vote down vote up
def contextMenuEvent(self, event: QContextMenuEvent):
        self.context_menu_position = event.pos()
        menu = self.create_context_menu()
        menu.exec_(self.mapToGlobal(event.pos()))
        self.context_menu_position = None 
Example 15
Project: urh   Author: jopohl   File: ListWidget.py    License: GNU General Public License v3.0 5 votes vote down vote up
def contextMenuEvent(self, event: QContextMenuEvent):
        self.context_menu_pos = event.pos()
        menu = self.create_context_menu()
        menu.exec_(self.mapToGlobal(event.pos()))
        self.context_menu_pos = None 
Example 16
Project: IDArling   Author: IDArlingTeam   File: filter.py    License: GNU General Public License v3.0 4 votes vote down vote up
def eventFilter(self, obj, ev):  # noqa: N802
        # Is it a QShowEvent on a QDialog named "Dialog"?
        if (
            ev.__class__ == ev,
            QShowEvent
            and obj.__class__ == QDialog
            and obj.windowTitle() == "About",
        ):
            # Find a child QGroupBox
            for groupBox in obj.children():
                if groupBox.__class__ == QGroupBox:
                    # Find a child QLabel with an icon
                    for label in groupBox.children():
                        if isinstance(label, QLabel) and label.pixmap():
                            self._replace_icon(label)

        # Is it a QContextMenuEvent on a QWidget?
        if isinstance(obj, QWidget) and isinstance(ev, QContextMenuEvent):
            # Find a parent titled "IDA View"
            parent = obj
            while parent:
                if parent.windowTitle().startswith("IDA View"):
                    # Intercept the next context menu
                    self._intercept = True
                parent = parent.parent()

        # Is it a QShowEvent on a QMenu?
        if isinstance(obj, QMenu) and isinstance(ev, QShowEvent):
            # Should we intercept?
            if self._intercept:
                self._insert_menu(obj)
                self._intercept = False

        # Is it a ToolTip event on a QWidget with a parent?
        if (
            ev.type() == QEvent.ToolTip
            and obj.__class__ == QWidget
            and obj.parent()
        ):
            table_view = obj.parent()
            # Is it a QTableView with a parent?
            if table_view.__class__ == QTableView and table_view.parent():
                func_window = table_view.parent()
                # Is it a QWidget titled "Functions window"?
                if (
                    func_window.__class__ == QWidget
                    and func_window.windowTitle() == "Functions window"
                ):
                    self._set_tooltip(obj, ev)

        return False