本文整理汇总了Python中PyQt5.Qt.QTreeWidget.setIndentation方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget.setIndentation方法的具体用法?Python QTreeWidget.setIndentation怎么用?Python QTreeWidget.setIndentation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QTreeWidget
的用法示例。
在下文中一共展示了QTreeWidget.setIndentation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CollapsibleDialog
# 需要导入模块: from PyQt5.Qt import QTreeWidget [as 别名]
# 或者: from PyQt5.Qt.QTreeWidget import setIndentation [as 别名]
class CollapsibleDialog(QDialog):
"""a dialog to which collapsible sections can be added;
reimplement define_sections() to define sections and
add them as (title, widget) tuples to self.sections
reimplemented from http://www.fancyaddress.com/blog/qt-2/create-something-like-the-widget-box-as-in-the-qt-designer/
"""
def __init__(self, parent = None):
super().__init__(parent)
self.tree = QTreeWidget()
self.tree.setHeaderHidden(True)
layout = QVBoxLayout()
layout.addWidget(self.tree)
self.setLayout(layout)
self.tree.setIndentation(0)
self.sections = []
self.section_dic = {}
self.define_sections()
self.add_sections()
def add_sections(self):
"""adds a collapsible sections for every
(title, widget) tuple in self.sections
"""
for (i, (title, widget)) in enumerate(self.sections):
button = self.add_button(title)
section = self.add_widget(button, widget)
button.addChild(section)
if i == 0:
button.setExpanded(True)
self.section_dic[i] = (button, section)
def define_sections(self):
"""reimplement this to define all your sections
and add them as (title, widget) tuples to self.sections
"""
widget = QFrame(self.tree)
layout = QHBoxLayout(widget)
layout.addWidget(QLabel("Bla"))
layout.addWidget(QLabel("Blubb"))
title = "Section 1"
self.sections.append((title, widget))
def add_button(self, title):
"""creates a QTreeWidgetItem containing a button
to expand or collapse its section
"""
item = QTreeWidgetItem()
self.tree.addTopLevelItem(item)
self.tree.setItemWidget(item, 0, SectionExpandButton(item, text = title))
return item
def add_widget(self, button, widget):
"""creates a QWidgetItem containing the widget,
as child of the button-QWidgetItem
"""
section = QTreeWidgetItem(button)
section.setDisabled(True)
self.tree.setItemWidget(section, 0, widget)
return section
@pyqtSlot(int, int)
def proceed_sections(self, old_section, new_section):
"""collapses old section and expands next section
"""
(button_new, _) = self.section_dic[new_section]
(button_old, _) = self.section_dic[old_section]
button_new.setExpanded(True)
button_old.setExpanded(False)
try:
self.sender().setChecked(False) # if sent from a button, un-press it
except:
pass