本文整理汇总了Python中PyQt5.Qt.QTreeWidgetItem.setData方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidgetItem.setData方法的具体用法?Python QTreeWidgetItem.setData怎么用?Python QTreeWidgetItem.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QTreeWidgetItem
的用法示例。
在下文中一共展示了QTreeWidgetItem.setData方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_item
# 需要导入模块: from PyQt5.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt5.Qt.QTreeWidgetItem import setData [as 别名]
def create_item(self, f, parent):
name = f.name
ans = QTreeWidgetItem(parent, [name])
ans.setData(0, Qt.UserRole, '/'.join(f.full_path[1:]))
ans.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
ans.setCheckState(0,
Qt.Unchecked if self.dev.is_folder_ignored(f.storage_id, f.full_path[1:]) else Qt.Checked)
ans.setData(0, Qt.DecorationRole, file_icon_provider().icon_from_ext('dir'))
return ans
示例2: process_node
# 需要导入模块: from PyQt5.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt5.Qt.QTreeWidgetItem import setData [as 别名]
def process_node(toc, parent):
for child in toc:
node = QTreeWidgetItem(parent)
node.setText(0, child.title or '')
node.setData(0, DEST_ROLE, child.dest or '')
node.setData(0, FRAG_ROLE, child.frag or '')
tt = _('File: {0}\nAnchor: {1}').format(
child.dest or '', child.frag or _('Top of file'))
node.setData(0, Qt.ToolTipRole, tt)
process_node(child, node)
示例3: unserialize_node
# 需要导入模块: from PyQt5.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt5.Qt.QTreeWidgetItem import setData [as 别名]
def unserialize_node(dict_node, parent):
n = QTreeWidgetItem(parent)
n.setData(0, Qt.DisplayRole, dict_node['title'])
n.setData(0, Qt.UserRole, dict_node['toc_node'])
n.setFlags(NODE_FLAGS)
n.setData(0, Qt.DecorationRole, dict_node['icon'])
n.setData(0, Qt.ToolTipRole, dict_node['tooltip'])
self.update_status_tip(n)
n.setExpanded(dict_node['is_expanded'])
n.setSelected(dict_node['is_selected'])
for c in dict_node['children']:
unserialize_node(c, n)
示例4: create_item
# 需要导入模块: from PyQt5.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt5.Qt.QTreeWidgetItem import setData [as 别名]
def create_item(name, linear=None):
imt = container.mime_map.get(name, guess_type(name))
icat = get_category(name, imt)
category = "text" if linear is not None else ({"text": "misc"}.get(icat, icat))
item = QTreeWidgetItem(self.categories["text" if linear is not None else category], 1)
flags = Qt.ItemIsEnabled | Qt.ItemIsSelectable
if category == "text":
flags |= Qt.ItemIsDragEnabled
if name not in cannot_be_renamed:
flags |= Qt.ItemIsEditable
item.setFlags(flags)
item.setStatusTip(0, _("Full path: ") + name)
item.setData(0, NAME_ROLE, name)
item.setData(0, CATEGORY_ROLE, category)
item.setData(0, LINEAR_ROLE, bool(linear))
item.setData(0, MIME_ROLE, imt)
set_display_name(name, item)
tooltips = []
emblems = []
if name in {cover_page_name, cover_image_name}:
emblems.append("default_cover.png")
tooltips.append(
_("This file is the cover %s for this book")
% (_("image") if name == cover_image_name else _("page"))
)
if name in container.opf_name:
emblems.append("metadata.png")
tooltips.append(_("This file contains all the metadata and book structure information"))
if imt == ncx_mime or name in nav_items:
emblems.append("toc.png")
tooltips.append(_("This file contains the metadata table of contents"))
if name not in manifested_names and not container.ok_to_be_unmanifested(name):
emblems.append("dialog_question.png")
tooltips.append(_("This file is not listed in the book manifest"))
if linear is False:
emblems.append("arrow-down.png")
tooltips.append(
_("This file is marked as non-linear in the spine\nDrag it to the top to make it linear")
)
if linear is None and icat == "text":
# Text item outside spine
emblems.append("dialog_warning.png")
tooltips.append(_("This file is a text file that is not referenced in the spine"))
if category == "text" and name in processed:
# Duplicate entry in spine
emblems.append("dialog_error.png")
tooltips.append(_("This file occurs more than once in the spine"))
render_emblems(item, emblems)
if tooltips:
item.setData(0, Qt.ToolTipRole, "\n".join(tooltips))
return item
示例5: browser_item
# 需要导入模块: from PyQt5.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt5.Qt.QTreeWidgetItem import setData [as 别名]
def browser_item(f, parent):
name = f.name
if not f.is_folder:
name += ' [%s]'%f.last_mod_string
ans = QTreeWidgetItem(parent, [name])
ans.setData(0, Qt.UserRole, f.full_path)
if f.is_folder:
ext = 'dir'
else:
ext = f.name.rpartition('.')[-1]
ans.setData(0, Qt.DecorationRole, file_icon_provider().icon_from_ext(ext))
return ans
示例6: process_duplicates
# 需要导入模块: from PyQt5.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt5.Qt.QTreeWidgetItem import setData [as 别名]
def process_duplicates(self, db, duplicates):
ta = _('%(title)s by %(author)s [%(formats)s]')
bf = QFont(self.dup_list.font())
bf.setBold(True)
itf = QFont(self.dup_list.font())
itf.setItalic(True)
for mi, cover, formats in duplicates:
# formats is a list of file paths
# Grab just the extension and display to the user
# Based only off the file name, no file type tests are done.
incoming_formats = ', '.join(os.path.splitext(path)[-1].replace('.', '').upper() for path in formats)
item = QTreeWidgetItem([ta%dict(
title=mi.title, author=mi.format_field('authors')[1],
formats=incoming_formats)] , 0)
item.setCheckState(0, Qt.Checked)
item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsUserCheckable)
item.setData(0, Qt.FontRole, bf)
item.setData(0, Qt.UserRole, (mi, cover, formats))
matching_books = db.books_with_same_title(mi)
def add_child(text):
c = QTreeWidgetItem([text], 1)
c.setFlags(Qt.ItemIsEnabled)
item.addChild(c)
return c
add_child(_('Already in calibre:')).setData(0, Qt.FontRole, itf)
for book_id in matching_books:
aut = [a.replace('|', ',') for a in (db.authors(book_id,
index_is_id=True) or '').split(',')]
add_child(ta%dict(
title=db.title(book_id, index_is_id=True),
author=authors_to_string(aut),
formats=db.formats(book_id, index_is_id=True,
verify_formats=False)))
add_child('')
yield item