本文整理汇总了Python中PyQt5.Qt.QTreeView.collapse方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeView.collapse方法的具体用法?Python QTreeView.collapse怎么用?Python QTreeView.collapse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QTreeView
的用法示例。
在下文中一共展示了QTreeView.collapse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Navigation
# 需要导入模块: from PyQt5.Qt import QTreeView [as 别名]
# 或者: from PyQt5.Qt.QTreeView import collapse [as 别名]
class Navigation(QWidget):
"""a navigation widget,
displaying all known projects and samples
"""
changed_projects = pyqtSignal(str, str)
changed_allele = pyqtSignal(str, int, str)
change_view = pyqtSignal(int)
refresh = pyqtSignal(str)
def __init__(self, log, settings):
self.log = log
self.settings = settings
super().__init__()
self.init_UI()
self.create_model()
self.tree.expand(self.open_node)
self.tree.clicked.connect(self.onClicked)
self.tree.setContextMenuPolicy(Qt.CustomContextMenu)
self.tree.customContextMenuRequested.connect(self.open_menu)
def init_UI(self):
"""creates the UI
"""
self.log.debug("Setting up Navigation area UI...")
self.tree = QTreeView()
self.tree.doubleClicked.connect(self.onDoubleClick)
self.grid = QGridLayout()
self.setLayout(self.grid)
self.header_lbl = QLabel("Projects and Samples:", self)
self.header_lbl.setStyleSheet(general.label_style_2nd)
self.grid.addWidget(self.header_lbl, 0,0)
self.grid.addWidget(self.tree, 1, 0)
header = self.tree.header()
header.hide()
self.log.debug("\t=> Done!")
def create_model(self):
"""creates or recreates the model
"""
self.log.debug("Updating Navigation area...")
root_node = Node("All")
openNode = Node("Open", root_node)
closedNode = Node("Closed", root_node)
project_nodes = {}
query = """select distinct sample_id_int, projects.project_name, project_status, allele_status, allele_nr
from projects left join alleles
on projects.project_name = alleles.project_name
order by project_status desc, projects.project_name desc, sample_id_int
"""
q = QtSql.QSqlQuery()
q.exec_(query)
while q.next():
sample = q.value(0)
project = q.value(1)
pstatus = q.value(2)
astatus = q.value(3)
nr = q.value(4)
try:
pnode = project_nodes[project]
except KeyError:
if pstatus == "Closed":
topnode = closedNode
else:
topnode = openNode
pnode = Node(project, topnode, "Project")
project_nodes[project] = pnode
if sample:
if nr != 1:
sample = "{} ({})".format(sample, nr)
Node(sample, pnode, "Sample", astatus)
self.model = NavigationModel(root_node)
self.tree.setModel(self.model)
self.open_node = self.model.index(0, 0, QModelIndex())
self.closed_node = self.model.index(1, 0, QModelIndex())
self.root_node = self.open_node.parent()
self.log.debug("\t=> Done!")
@pyqtSlot(str, str)
def expand_project(self, project, status = None):
"""expands the node of the given project,
returns its index and parent-node's index
"""
self.log.debug("Expanding project {} ({})...".format(project, status))
if not status in (None, "Open", "Closed"):
return None, None
myindex = self.open_node
myparent_node = self.open_node
if status == "Open":
self.log.debug("Open")
parent_node = self.open_node
self.tree.expand(parent_node)
self.tree.collapse(self.closed_node)
elif status == "Closed":
self.log.debug("Closed")
parent_node = self.closed_node
#.........这里部分代码省略.........