本文整理汇总了Python中PyQt5.QtCore.QAbstractItemModel方法的典型用法代码示例。如果您正苦于以下问题:Python QtCore.QAbstractItemModel方法的具体用法?Python QtCore.QAbstractItemModel怎么用?Python QtCore.QAbstractItemModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore
的用法示例。
在下文中一共展示了QtCore.QAbstractItemModel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: data
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractItemModel [as 别名]
def data(self, index, role=Qt.DisplayRole):
"""Return the item data for index.
Override QAbstractItemModel::data.
Args:
index: The QModelIndex to get item flags for.
Return: The item data, or None on an invalid index.
"""
if role != Qt.DisplayRole:
return None
cat = self._cat_from_idx(index)
if cat:
# category header
if index.column() == 0:
return self._categories[index.row()].name
return None
# item
cat = self._cat_from_idx(index.parent())
if not cat:
return None
idx = cat.index(index.row(), index.column())
return cat.data(idx)
示例2: flags
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractItemModel [as 别名]
def flags(self, index):
"""Return the item flags for index.
Override QAbstractItemModel::flags.
Return: The item flags, or Qt.NoItemFlags on error.
"""
if not index.isValid():
return Qt.NoItemFlags
if index.parent().isValid():
# item
return (Qt.ItemIsEnabled | Qt.ItemIsSelectable |
Qt.ItemNeverHasChildren)
else:
# category
return Qt.NoItemFlags
示例3: index
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractItemModel [as 别名]
def index(self, row, col, parent=QModelIndex()):
"""Get an index into the model.
Override QAbstractItemModel::index.
Return: A QModelIndex.
"""
if (row < 0 or row >= self.rowCount(parent) or
col < 0 or col >= self.columnCount(parent)):
return QModelIndex()
if parent.isValid():
if parent.column() != 0:
return QModelIndex()
# store a pointer to the parent category in internalPointer
return self.createIndex(row, col, self._categories[parent.row()])
return self.createIndex(row, col, None)
示例4: __init__
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractItemModel [as 别名]
def __init__(self, *, column_widths=(30, 70, 0), parent=None):
super().__init__(parent)
self.column_widths = column_widths
self._categories = [
] # type: typing.MutableSequence[QAbstractItemModel]
示例5: parent
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractItemModel [as 别名]
def parent(self, index):
"""Get an index to the parent of the given index.
Override QAbstractItemModel::parent.
Args:
index: The QModelIndex to get the parent index for.
"""
parent_cat = index.internalPointer()
if not parent_cat:
# categories have no parent
return QModelIndex()
row = self._categories.index(parent_cat)
return self.createIndex(row, 0, None)
示例6: columnCount
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractItemModel [as 别名]
def columnCount(self, parent=QModelIndex()):
"""Override QAbstractItemModel::columnCount."""
# pylint: disable=unused-argument
return 3
示例7: setModelData
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractItemModel [as 别名]
def setModelData(self, editor: QWidget, model: QAbstractItemModel,
qindex: QModelIndex):
if isinstance(editor, QComboBox):
value = editor.currentData(Qt.UserRole)
model.setData(qindex, value, Qt.EditRole)
else:
super().setModelData(editor, model, qindex)
示例8: __init__
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractItemModel [as 别名]
def __init__(self, columns):
QtCore.QAbstractItemModel.__init__(self)
self._root = CustomNode(list(itertools.repeat("", len(columns))))
self.signals = CustomModelSignals()
self._columns = columns
示例9: parent
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractItemModel [as 别名]
def parent(self, in_index: QModelIndex = None):
if in_index.isValid():
parent = in_index.internalPointer().parent
if parent:
return QtCore.QAbstractItemModel.createIndex(self, parent.row, 0, parent)
return QtCore.QModelIndex()
示例10: index
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractItemModel [as 别名]
def index(self, row: int, column: int, parent=None, *args, **kwargs):
if not parent or not parent.isValid():
parent_node = self._root
else:
parent_node = parent.internalPointer()
if not QtCore.QAbstractItemModel.hasIndex(self, row, column, parent):
return QtCore.QModelIndex()
child = parent_node.child(row)
if child:
return QtCore.QAbstractItemModel.createIndex(self, row, column, child)
else:
return QtCore.QModelIndex()
示例11: setModelData
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractItemModel [as 别名]
def setModelData(self, editor: QCheckBox, model: QAbstractItemModel, index: QModelIndex):
model.setData(index, editor.isChecked(), Qt.EditRole)
示例12: setModelData
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractItemModel [as 别名]
def setModelData(self, editor: QWidget, model: QAbstractItemModel, index: QModelIndex):
if isinstance(editor, ExternalProgramWidget):
model.setData(index, editor.line_edit_external_program.text(), Qt.EditRole)
elif isinstance(editor, RandomValueWidget):
model.setData(index, [editor.spinbox_random_min.value(), editor.spinbox_random_max.value()], Qt.EditRole)
else:
super().setModelData(editor, model, index)
示例13: setModelData
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractItemModel [as 别名]
def setModelData(self, editor: QWidget, model: QAbstractItemModel, index: QModelIndex):
if self.return_index:
model.setData(index, editor.currentIndex(), Qt.EditRole)
else:
model.setData(index, editor.currentText(), Qt.EditRole)
示例14: setModelData
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractItemModel [as 别名]
def setModelData(self, editor: QWidget, model: QAbstractItemModel, index: QModelIndex):
model.setData(index, editor.value(), Qt.EditRole)
示例15: setModelData
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QAbstractItemModel [as 别名]
def setModelData(self, editor: QWidget, model: QAbstractItemModel, index: QModelIndex):
model.setData(index, editor.currentText(), Qt.EditRole)