本文整理汇总了Python中PyQt5.Qt.QTreeView.mapToGlobal方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeView.mapToGlobal方法的具体用法?Python QTreeView.mapToGlobal怎么用?Python QTreeView.mapToGlobal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QTreeView
的用法示例。
在下文中一共展示了QTreeView.mapToGlobal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Navigation
# 需要导入模块: from PyQt5.Qt import QTreeView [as 别名]
# 或者: from PyQt5.Qt.QTreeView import mapToGlobal [as 别名]
#.........这里部分代码省略.........
@pyqtSlot(QModelIndex)
def onClicked(self, index):
"""emits signals when a project or sample is selected
"""
data = self.model.data(index, Qt.DisplayRole)
nodetype = self.model.nodeType(index)
if nodetype == "Sample":
if ("(") in data:
data = data.split("(")
sample = data[0].strip()
nr = int(data[1].strip()[:-1])
else:
sample = data
nr = 1
project = self.model.data(self.model.parent(index), Qt.DisplayRole)
self.changed_allele.emit(sample, nr, project)
self.log.debug("Navigation emitted 'Allele changed to {} #{} (project {})'".format(sample, nr, project))
elif nodetype == "Project":
status = self.model.data(self.model.parent(index), Qt.DisplayRole)
self.changed_projects.emit(data, status)
self.log.debug("Navigation emitted 'Project changed to {}'".format(data))
@pyqtSlot(QPoint)
def open_menu(self, pos):
"""provides a context menu
"""
index = self.tree.indexAt(pos)
nodetype = self.model.nodeType(index)
self.log.debug("Opening navigation menu...")
if nodetype == "Project":
menu = QMenu()
open_project_act = menu.addAction("Open Project View")
action = menu.exec_(self.tree.mapToGlobal(pos))
if action == open_project_act:
project = self.model.data(index, Qt.DisplayRole)
status = self.model.data(self.model.parent(index), Qt.DisplayRole)
self.changed_projects.emit(project, status)
self.change_view.emit(3)
self.log.debug("Navigation emitted changed_projects & change_view to ProjectView")
elif nodetype == "Sample":
menu = QMenu()
open_sample_act = menu.addAction("Open Sample View")
delete_sample_act = menu.addAction("Delete Allele (admin-only!)")
action = menu.exec_(self.tree.mapToGlobal(pos))
if action:
sample_list = self.model.data(index, Qt.DisplayRole).split()
sample = sample_list[0]
if len(sample_list) > 1:
nr = int(sample_list[1][1:-1])
else:
nr = 1
project = self.model.data(self.model.parent(index), Qt.DisplayRole)
status = self.model.data(self.model.parent(self.model.parent(index)), Qt.DisplayRole)
if action == open_sample_act:
try:
self.changed_allele.emit(sample, nr, project)
self.change_view.emit(4)
self.log.debug("Navigation emitted changed_alleles & change_view to AlleleView")
except Exception as E:
self.log.exception(E)
elif action == delete_sample_act:
self.log.info("Deleting {} #{} of project {}".format(sample, nr, project))