本文整理汇总了Python中PyQt5.QtCore.QAbstractListModel方法的典型用法代码示例。如果您正苦于以下问题:Python QtCore.QAbstractListModel方法的具体用法?Python QtCore.QAbstractListModel怎么用?Python QtCore.QAbstractListModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore
的用法示例。
在下文中一共展示了QtCore.QAbstractListModel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rowCount
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractListModel [as 别名]
def rowCount(self, parent = None) -> int:
"""This function is necessary because it is abstract in QAbstractListModel.
Under the hood, Qt will call this function when it needs to know how
many items are in the model.
This pyqtSlot will not be linked to the itemsChanged signal, so please
use the normal count() function instead.
"""
return self.count
示例2: data
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractListModel [as 别名]
def data(self, index, role):
"""Reimplemented from QAbstractListModel"""
if not index.isValid():
return QVariant()
return self._items[index.row()][self._role_names[role].decode("utf-8")]
示例3: count
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractListModel [as 别名]
def count(self) -> int:
"""Reimplemented from QAbstractListModel
Note that count() is overridden from QAbstractItemModel. The signature
of the method in that class is "int count()" which makes this slot
declaration incorrect.
TODO: fix the pointer when actually using this parameter.
"""
if not self._container:
return 0
return len(self._row_index_list)
示例4: rowCount
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractListModel [as 别名]
def rowCount(self, parent = None) -> int:
"""This function is necessary because it is abstract in QAbstractListModel.
Under the hood, Qt will call this function when it needs to know how many items are in the model.
This pyqtSlot will not be linked to the itemsChanged signal, so please use the normal count() function instead.
"""
return self.count
示例5: data
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractListModel [as 别名]
def data(self, index, role):
"""Reimplemented from QAbstractListModel"""
if not self._container:
return QVariant()
if not index.isValid():
return QVariant()
if role not in self._role_names:
return QVariant()
try:
definition = self._definition_list[self._row_index_list[index.row()]]
except IndexError:
# Definition is not visible or completely not in the list
return QVariant()
if role == self.KeyRole:
return definition.key
elif role == self.DepthRole:
return len(definition.getAncestors())
elif role == self.VisibleRole:
return definition.key in self._visible
elif role == self.ExpandedRole:
return definition.key in self._expanded
role_name = self._role_names[role]
try:
data = getattr(definition, role_name.decode())
except AttributeError:
data = ""
if isinstance(data, collections.OrderedDict):
result = []
for key, value in data.items():
if self._i18n_catalog:
value = self._i18n_catalog.i18nc(definition.key + " option " + key, value)
result.append({"key": key, "value": value})
return result
if isinstance(data, str) and self._i18n_catalog:
data = self._i18n_catalog.i18nc(definition.key + " " + role_name.decode(), data)
return data