当前位置: 首页>>代码示例>>Python>>正文


Python QTreeView.indexAt方法代码示例

本文整理汇总了Python中PyQt5.Qt.QTreeView.indexAt方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeView.indexAt方法的具体用法?Python QTreeView.indexAt怎么用?Python QTreeView.indexAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.Qt.QTreeView的用法示例。


在下文中一共展示了QTreeView.indexAt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Navigation

# 需要导入模块: from PyQt5.Qt import QTreeView [as 别名]
# 或者: from PyQt5.Qt.QTreeView import indexAt [as 别名]

#.........这里部分代码省略.........
            except Exception as E:
                self.log.error(E)
                self.log.exception(E)
        self.select_project(project)
        self.log.debug("\t=> project found ({}) and successfully expanded".format(status))
        return myindex, myparent_node
    
    @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)
开发者ID:DKMS-LSL,项目名称:typeloader,代码行数:70,代码来源:GUI_navigation.py


注:本文中的PyQt5.Qt.QTreeView.indexAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。