本文整理汇总了Python中PyQt5.QtWidgets.QTreeWidget.resizeColumnToContents方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget.resizeColumnToContents方法的具体用法?Python QTreeWidget.resizeColumnToContents怎么用?Python QTreeWidget.resizeColumnToContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTreeWidget
的用法示例。
在下文中一共展示了QTreeWidget.resizeColumnToContents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ChangedDocumentsListDialog
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import resizeColumnToContents [as 别名]
#.........这里部分代码省略.........
for i in d.takeChildren():
i.doc = None
# group the documents by directory
dirs = {}
for d in documents:
path = d.url().toLocalFile()
if path:
dirname, filename = os.path.split(path)
dirs.setdefault(dirname, []).append((filename, d))
for dirname in sorted(dirs, key=util.naturalsort):
diritem = QTreeWidgetItem()
diritem.setText(0, util.homify(dirname))
self.tree.addTopLevelItem(diritem)
diritem.setExpanded(True)
diritem.setFlags(Qt.ItemIsEnabled)
diritem.setIcon(0, icons.get('folder-open'))
for filename, document in sorted(dirs[dirname],
key=lambda item: util.naturalsort(item[0])):
fileitem = QTreeWidgetItem()
diritem.addChild(fileitem)
if documentwatcher.DocumentWatcher.instance(document).isdeleted():
itemtext = _("[deleted]")
icon = "dialog-error"
else:
itemtext = _("[modified]")
icon = "document-edit"
fileitem.setIcon(0, icons.get(icon))
fileitem.setText(0, filename)
fileitem.setText(1, itemtext)
fileitem.doc = document
# select the item if there is only one
if len(dirs) == 1 and len(list(dirs.values())[0]) == 1:
fileitem.setSelected(True)
self.tree.resizeColumnToContents(0)
self.tree.resizeColumnToContents(1)
self.updateButtons()
def removeDocument(self, document):
"""Remove the specified document from our list."""
for d in range(self.tree.topLevelItemCount()):
diritem = self.tree.topLevelItem(d)
for f in range(diritem.childCount()):
if diritem.child(f).doc is document:
i = diritem.takeChild(f)
i.doc = None
if diritem.childCount() == 0:
self.tree.takeTopLevelItem(d)
break
else:
continue
break
self.updateButtons()
# hide if no documents are left
if self.tree.topLevelItemCount() == 0:
self.hide()
def selectedDocuments(self):
"""Return the selected documents."""
return [i.doc for i in self.tree.selectedItems()]
def allDocuments(self):
"""Return all shown documents."""
return [self.tree.topLevelItem(d).child(f).doc
for d in range(self.tree.topLevelItemCount())
for f in range(self.tree.topLevelItem(d).childCount())]
示例2: Shortcuts
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import resizeColumnToContents [as 别名]
#.........这里部分代码省略.........
# show actions that are left, grouped by collection
titlegroups = {}
for a in left[:]: # copy
collection, name = allactions[a]
if collection.title():
titlegroups.setdefault(collection.title(), []).append(a)
left.remove(a)
for title in sorted(titlegroups):
item = QTreeWidgetItem(["{0}:".format(title)])
for a in titlegroups[title]:
item.addChild(ShortcutItem(a, *allactions[a]))
self.tree.addTopLevelItem(item)
item.setFlags(Qt.ItemIsEnabled) # disable selection
# show other actions that were not in the menus
item = QTreeWidgetItem([_("Other commands:")])
for a in left:
if a.text() and not a.menu():
item.addChild(ShortcutItem(a, *allactions[a]))
if item.childCount():
self.tree.addTopLevelItem(item)
item.setFlags(Qt.ItemIsEnabled) # disable selection
self.tree.expandAll()
item = self.tree.topLevelItem(0).child(0)
if _lastaction:
# find the previously selected item
for i in self.items():
if i.name == _lastaction:
item = i
break
self.tree.setCurrentItem(item)
self.tree.resizeColumnToContents(0)
def items(self):
"""Yield all the items in the actions tree."""
def children(item):
for i in range(item.childCount()):
c = item.child(i)
if c.childCount():
for c1 in children(c):
yield c1
else:
yield c
for c in children(self.tree.invisibleRootItem()):
yield c
def item(self, collection, name):
for item in self.items():
if item.collection.name == collection and item.name == name:
return item
def saveSettings(self):
self.scheme.saveSettings("shortcut_scheme", "shortcut_schemes", "shortcuts")
for item in self.items():
for scheme in self.scheme.schemes():
item.save(scheme)
item.clearSettings()
item.switchScheme(self.scheme.currentScheme())
def loadSettings(self):
self.scheme.loadSettings("shortcut_scheme", "shortcut_schemes")
# clear the settings in all the items
for item in self.items():
item.clearSettings()