本文整理汇总了Python中AnyQt.QtGui.QStandardItem.setData方法的典型用法代码示例。如果您正苦于以下问题:Python QStandardItem.setData方法的具体用法?Python QStandardItem.setData怎么用?Python QStandardItem.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtGui.QStandardItem
的用法示例。
在下文中一共展示了QStandardItem.setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _cat_desc_to_std_item
# 需要导入模块: from AnyQt.QtGui import QStandardItem [as 别名]
# 或者: from AnyQt.QtGui.QStandardItem import setData [as 别名]
def _cat_desc_to_std_item(self, desc):
"""
Create a QStandardItem for the category description.
"""
item = QStandardItem()
item.setText(desc.name)
if desc.icon:
icon = desc.icon
else:
icon = "icons/default-category.svg"
icon = icon_loader.from_description(desc).get(icon)
item.setIcon(icon)
if desc.background:
background = desc.background
else:
background = DEFAULT_COLOR
background = NAMED_COLORS.get(background, background)
brush = QBrush(QColor(background))
item.setData(brush, self.BACKGROUND_ROLE)
tooltip = desc.description if desc.description else desc.name
item.setToolTip(tooltip)
item.setFlags(Qt.ItemIsEnabled)
item.setData(desc, self.CATEGORY_DESC_ROLE)
return item
示例2: list_docs
# 需要导入模块: from AnyQt.QtGui import QStandardItem [as 别名]
# 或者: from AnyQt.QtGui.QStandardItem import setData [as 别名]
def list_docs(self):
""" List documents into the left scrolling area """
search_keyword = self.filter_input.text().strip('|')
try:
reg = re.compile(search_keyword, re.IGNORECASE)
except sre_constants.error:
return
def is_match(x):
return not bool(search_keyword) or reg.search(x)
self.output_mask.clear()
self.doc_list_model.clear()
for i, (doc, title, content) in enumerate(zip(self.corpus, self.corpus.titles,
self.corpus_docs)):
if is_match(content):
item = QStandardItem()
item.setData(title, Qt.DisplayRole)
item.setData(doc, Qt.UserRole)
self.doc_list_model.appendRow(item)
self.output_mask.append(i)
if self.doc_list_model.rowCount() > 0:
self.doc_list.selectRow(0) # Select the first document
else:
self.doc_webview.setHtml('')
self.commit()
示例3: _initialize
# 需要导入模块: from AnyQt.QtGui import QStandardItem [as 别名]
# 或者: from AnyQt.QtGui.QStandardItem import setData [as 别名]
def _initialize(self):
for pp_def in PREPROCESSORS:
description = pp_def.description
if description.icon:
icon = QIcon(description.icon)
else:
icon = QIcon()
item = QStandardItem(icon, description.title)
item.setToolTip(description.summary or "")
item.setData(pp_def, DescriptionRole)
item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable |
Qt.ItemIsDragEnabled)
self.preprocessors.appendRow([item])
try:
model = self.load(self.storedsettings)
except Exception:
model = self.load({})
self.set_model(model)
if not model.rowCount():
# enforce default width constraint if no preprocessors
# are instantiated (if the model is not empty the constraints
# will be triggered by LayoutRequest event on the `flow_view`)
self.__update_size_constraint()
self.apply()
示例4: row_for_state
# 需要导入模块: from AnyQt.QtGui import QStandardItem [as 别名]
# 或者: from AnyQt.QtGui.QStandardItem import setData [as 别名]
def row_for_state(self, score, state):
"""The row consists of attributes sorted by name; class is at the
beginning, if present, so it's on the x-axis and not lost somewhere."""
class_var = self.master.color_data.domain.class_var
attrs = tuple(
sorted((self.attr_ordering[x] for x in state),
key=lambda attr: (1 - (attr is class_var), attr.name)))
item = QStandardItem(", ".join(a.name for a in attrs))
item.setData(attrs, self._AttrRole)
return [item]
示例5: color_palette_model
# 需要导入模块: from AnyQt.QtGui import QStandardItem [as 别名]
# 或者: from AnyQt.QtGui.QStandardItem import setData [as 别名]
def color_palette_model(palettes, iconsize=QSize(64, 16)):
model = QStandardItemModel()
for name, palette in palettes:
_, colors = max(palette.items())
colors = [QColor(*c) for c in colors]
item = QStandardItem(name)
item.setIcon(QIcon(palette_pixmap(colors, iconsize)))
item.setData(palette, Qt.UserRole)
model.appendRow([item])
return model
示例6: RecentPath_asqstandarditem
# 需要导入模块: from AnyQt.QtGui import QStandardItem [as 别名]
# 或者: from AnyQt.QtGui.QStandardItem import setData [as 别名]
def RecentPath_asqstandarditem(pathitem):
icon_provider = QFileIconProvider()
# basename of a normalized name (strip right path component separators)
basename = os.path.basename(os.path.normpath(pathitem.abspath))
item = QStandardItem(
icon_provider.icon(QFileInfo(pathitem.abspath)),
basename
)
item.setToolTip(pathitem.abspath)
item.setData(pathitem, Qt.UserRole)
return item
示例7: row_for_state
# 需要导入模块: from AnyQt.QtGui import QStandardItem [as 别名]
# 或者: from AnyQt.QtGui.QStandardItem import setData [as 别名]
def row_for_state(self, score, state):
attrs = sorted((self.attrs[x] for x in state), key=attrgetter("name"))
attr_items = []
for attr in attrs:
item = QStandardItem(attr.name)
item.setData(attrs, self._AttrRole)
item.setData(Qt.AlignLeft + Qt.AlignTop, Qt.TextAlignmentRole)
item.setToolTip(attr.name)
attr_items.append(item)
correlation_item = QStandardItem("{:+.3f}".format(score[1]))
correlation_item.setData(score[2], self.PValRole)
correlation_item.setData(attrs, self._AttrRole)
correlation_item.setData(
self.NEGATIVE_COLOR if score[1] < 0 else self.POSITIVE_COLOR,
gui.TableBarItem.BarColorRole)
return [correlation_item] + attr_items
示例8: item
# 需要导入模块: from AnyQt.QtGui import QStandardItem [as 别名]
# 或者: from AnyQt.QtGui.QStandardItem import setData [as 别名]
def item(value=None, tooltip=None, user=None):
si = QStandardItem()
if value is not None:
si.setData(value, Qt.DisplayRole)
if tooltip is not None:
si.setData(tooltip, Qt.ToolTipRole)
if user is not None:
si.setData(user, Qt.UserRole)
else:
si.setData(value, Qt.UserRole)
return si
示例9: row_for_state
# 需要导入模块: from AnyQt.QtGui import QStandardItem [as 别名]
# 或者: from AnyQt.QtGui.QStandardItem import setData [as 别名]
def row_for_state(self, score, state):
attrs = sorted((self.attrs[x] for x in state), key=attrgetter("name"))
attrs_item = QStandardItem(
"{}, {}".format(attrs[0].name, attrs[1].name))
attrs_item.setData(attrs, self._AttrRole)
attrs_item.setData(Qt.AlignLeft + Qt.AlignTop, Qt.TextAlignmentRole)
correlation_item = QStandardItem("{:+.3f}".format(score[1]))
correlation_item.setData(attrs, self._AttrRole)
correlation_item.setData(
self.NEGATIVE_COLOR if score[1] < 0 else self.POSITIVE_COLOR,
gui.TableBarItem.BarColorRole)
return [correlation_item, attrs_item]
示例10: test_tooltree
# 需要导入模块: from AnyQt.QtGui import QStandardItem [as 别名]
# 或者: from AnyQt.QtGui.QStandardItem import setData [as 别名]
def test_tooltree(self):
tree = ToolTree()
role = tree.actionRole()
model = QStandardItemModel()
tree.setModel(model)
item = QStandardItem("One")
item.setData(QAction("One", tree), role)
model.appendRow([item])
cat = QStandardItem("A Category")
item = QStandardItem("Two")
item.setData(QAction("Two", tree), role)
cat.appendRow([item])
item = QStandardItem("Three")
item.setData(QAction("Three", tree), role)
cat.appendRow([item])
model.appendRow([cat])
def p(action):
print("triggered", action.text())
tree.triggered.connect(p)
tree.show()
self.app.exec_()
示例11: __activated
# 需要导入模块: from AnyQt.QtGui import QStandardItem [as 别名]
# 或者: from AnyQt.QtGui.QStandardItem import setData [as 别名]
def __activated(self, index):
item = self.preprocessors.itemFromIndex(index)
action = item.data(DescriptionRole)
item = QStandardItem()
item.setData({}, ParametersRole)
item.setData(action.description.title, Qt.DisplayRole)
item.setData(action, DescriptionRole)
self.preprocessormodel.appendRow([item])
示例12: load
# 需要导入模块: from AnyQt.QtGui import QStandardItem [as 别名]
# 或者: from AnyQt.QtGui.QStandardItem import setData [as 别名]
def load(self, saved):
"""Load a preprocessor list from a dict."""
name = saved.get("name", "")
preprocessors = saved.get("preprocessors", [])
model = StandardItemModel()
def dropMimeData(data, action, row, column, parent):
if data.hasFormat("application/x-qwidget-ref") and \
action == Qt.CopyAction:
qname = bytes(data.data("application/x-qwidget-ref")).decode()
ppdef = self._qname2ppdef[qname]
item = QStandardItem(ppdef.description.title)
item.setData({}, ParametersRole)
item.setData(ppdef.description.title, Qt.DisplayRole)
item.setData(ppdef, DescriptionRole)
self.preprocessormodel.insertRow(row, [item])
return True
else:
return False
model.dropMimeData = dropMimeData
for qualname, params in preprocessors:
pp_def = self._qname2ppdef[qualname]
description = pp_def.description
item = QStandardItem(description.title)
if description.icon:
icon = QIcon(description.icon)
else:
icon = QIcon()
item.setIcon(icon)
item.setToolTip(description.summary)
item.setData(pp_def, DescriptionRole)
item.setData(params, ParametersRole)
model.appendRow(item)
return model
示例13: _sum_item
# 需要导入模块: from AnyQt.QtGui import QStandardItem [as 别名]
# 或者: from AnyQt.QtGui.QStandardItem import setData [as 别名]
def _sum_item(value, border=""):
item = QStandardItem()
item.setData(value, Qt.DisplayRole)
item.setTextAlignment(Qt.AlignRight | Qt.AlignVCenter)
item.setFlags(Qt.ItemIsEnabled)
item.setFont(bold_font)
item.setData(border, BorderRole)
item.setData(QColor(192, 192, 192), BorderColorRole)
return item
示例14: list_docs
# 需要导入模块: from AnyQt.QtGui import QStandardItem [as 别名]
# 或者: from AnyQt.QtGui.QStandardItem import setData [as 别名]
def list_docs(self):
""" List documents into the left scrolling area """
if self.corpus_docs is None:
return
search_keyword = self.regexp_filter.strip('|')
try:
reg = re.compile(search_keyword, re.IGNORECASE)
except sre_constants.error:
return
def is_match(x):
return not bool(search_keyword) or reg.search(x)
self.output_mask.clear()
self.doc_list_model.clear()
for i, (doc, title, content) in enumerate(zip(self.corpus, self.corpus.titles,
self.corpus_docs)):
if is_match(content):
item = QStandardItem()
item.setData(title, Qt.DisplayRole)
item.setData(doc, Qt.UserRole)
self.doc_list_model.appendRow(item)
self.output_mask.append(i)
示例15: dropMimeData
# 需要导入模块: from AnyQt.QtGui import QStandardItem [as 别名]
# 或者: from AnyQt.QtGui.QStandardItem import setData [as 别名]
def dropMimeData(data, action, row, column, parent):
if data.hasFormat("application/x-qwidget-ref") and \
action == Qt.CopyAction:
qname = bytes(data.data("application/x-qwidget-ref")).decode()
ppdef = self._qname2ppdef[qname]
item = QStandardItem(ppdef.description.title)
item.setData({}, ParametersRole)
item.setData(ppdef.description.title, Qt.DisplayRole)
item.setData(ppdef, DescriptionRole)
self.preprocessormodel.insertRow(row, [item])
return True
else:
return False