本文整理汇总了Python中PyQt5.QtGui.QContextMenuEvent方法的典型用法代码示例。如果您正苦于以下问题:Python QtGui.QContextMenuEvent方法的具体用法?Python QtGui.QContextMenuEvent怎么用?Python QtGui.QContextMenuEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui
的用法示例。
在下文中一共展示了QtGui.QContextMenuEvent方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: contextMenuEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QContextMenuEvent [as 别名]
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())
示例2: event
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QContextMenuEvent [as 别名]
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)
示例3: contextMenuEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QContextMenuEvent [as 别名]
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))
示例4: contextMenuEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QContextMenuEvent [as 别名]
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()))
示例5: contextMenuEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QContextMenuEvent [as 别名]
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()))
示例6: contextMenuEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QContextMenuEvent [as 别名]
def contextMenuEvent(self, event: QContextMenuEvent):
pass
示例7: contextMenuEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QContextMenuEvent [as 别名]
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
示例8: contextMenuEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QContextMenuEvent [as 别名]
def contextMenuEvent(self, event: QContextMenuEvent):
self.create_context_menu().exec_(self.mapToGlobal(event.pos()))
示例9: contextMenuEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QContextMenuEvent [as 别名]
def contextMenuEvent(self, event: QContextMenuEvent):
menu = self.create_context_menu()
menu.exec_(self.mapToGlobal(event.pos()))
示例10: contextMenuEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QContextMenuEvent [as 别名]
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
示例11: contextMenuEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QContextMenuEvent [as 别名]
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
示例12: contextMenuEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QContextMenuEvent [as 别名]
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
示例13: eventFilter
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QContextMenuEvent [as 别名]
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