Python PyQt5.QtCore.QAbstractItemModel() Examples
The following are 16 code examples for showing how to use PyQt5.QtCore.QAbstractItemModel(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
PyQt5.QtCore
, or try the search function
.
Example 1
Project: qutebrowser Author: qutebrowser File: completionmodel.py License: GNU General Public License v3.0 | 6 votes |
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)
Example 2
Project: qutebrowser Author: qutebrowser File: completionmodel.py License: GNU General Public License v3.0 | 6 votes |
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
Example 3
Project: qutebrowser Author: qutebrowser File: completionmodel.py License: GNU General Public License v3.0 | 6 votes |
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)
Example 4
Project: qutebrowser Author: qutebrowser File: completionmodel.py License: GNU General Public License v3.0 | 5 votes |
def __init__(self, *, column_widths=(30, 70, 0), parent=None): super().__init__(parent) self.column_widths = column_widths self._categories = [ ] # type: typing.MutableSequence[QAbstractItemModel]
Example 5
Project: qutebrowser Author: qutebrowser File: completionmodel.py License: GNU General Public License v3.0 | 5 votes |
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)
Example 6
Project: qutebrowser Author: qutebrowser File: completionmodel.py License: GNU General Public License v3.0 | 5 votes |
def columnCount(self, parent=QModelIndex()): """Override QAbstractItemModel::columnCount.""" # pylint: disable=unused-argument return 3
Example 7
Project: mhw_armor_edit Author: fre-sch File: utils.py License: The Unlicense | 5 votes |
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)
Example 8
Project: CvStudio Author: haruiz File: treeview_model.py License: MIT License | 5 votes |
def __init__(self, columns): QtCore.QAbstractItemModel.__init__(self) self._root = CustomNode(list(itertools.repeat("", len(columns)))) self.signals = CustomModelSignals() self._columns = columns
Example 9
Project: CvStudio Author: haruiz File: treeview_model.py License: MIT License | 5 votes |
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()
Example 10
Project: CvStudio Author: haruiz File: treeview_model.py License: MIT License | 5 votes |
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()
Example 11
Project: urh Author: jopohl File: CheckBoxDelegate.py License: GNU General Public License v3.0 | 5 votes |
def setModelData(self, editor: QCheckBox, model: QAbstractItemModel, index: QModelIndex): model.setData(index, editor.isChecked(), Qt.EditRole)
Example 12
Project: urh Author: jopohl File: ProtocolValueDelegate.py License: GNU General Public License v3.0 | 5 votes |
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)
Example 13
Project: urh Author: jopohl File: ComboBoxDelegate.py License: GNU General Public License v3.0 | 5 votes |
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)
Example 14
Project: urh Author: jopohl File: SpinBoxDelegate.py License: GNU General Public License v3.0 | 5 votes |
def setModelData(self, editor: QWidget, model: QAbstractItemModel, index: QModelIndex): model.setData(index, editor.value(), Qt.EditRole)
Example 15
Project: urh Author: jopohl File: SectionComboBoxDelegate.py License: GNU General Public License v3.0 | 5 votes |
def setModelData(self, editor: QWidget, model: QAbstractItemModel, index: QModelIndex): model.setData(index, editor.currentText(), Qt.EditRole)
Example 16
Project: qutebrowser Author: qutebrowser File: urlmodel.py License: GNU General Public License v3.0 | 4 votes |
def url(*, info): """A model which combines various URLs. This combines: - bookmarks - quickmarks - search engines - web history URLs Used for the `open` command. """ model = completionmodel.CompletionModel(column_widths=(40, 50, 10)) # pylint: disable=bad-config-option quickmarks = [(url, name) for (name, url) in objreg.get('quickmark-manager').marks.items()] bookmarks = objreg.get('bookmark-manager').marks.items() searchengines = [(k, v) for k, v in sorted(config.val.url.searchengines.items()) if k != 'DEFAULT'] # pylint: enable=bad-config-option categories = config.val.completion.open_categories models = {} # type: typing.Dict[str, QAbstractItemModel] if searchengines and 'searchengines' in categories: models['searchengines'] = listcategory.ListCategory( 'Search engines', searchengines, sort=False) if quickmarks and 'quickmarks' in categories: models['quickmarks'] = listcategory.ListCategory( 'Quickmarks', quickmarks, delete_func=_delete_quickmark, sort=False) if bookmarks and 'bookmarks' in categories: models['bookmarks'] = listcategory.ListCategory( 'Bookmarks', bookmarks, delete_func=_delete_bookmark, sort=False) history_disabled = info.config.get('completion.web_history.max_items') == 0 if not history_disabled and 'history' in categories: hist_cat = histcategory.HistoryCategory(delete_func=_delete_history) models['history'] = hist_cat for category in categories: if category in models: model.add_category(models[category]) return model