当前位置: 首页>>代码示例>>Python>>正文


Python QtCore.QModelIndex方法代码示例

本文整理汇总了Python中PyQt5.QtCore.QModelIndex方法的典型用法代码示例。如果您正苦于以下问题:Python QtCore.QModelIndex方法的具体用法?Python QtCore.QModelIndex怎么用?Python QtCore.QModelIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtCore的用法示例。


在下文中一共展示了QtCore.QModelIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: data

# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QModelIndex [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) 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:26,代码来源:completionmodel.py

示例2: index

# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QModelIndex [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) 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:18,代码来源:completionmodel.py

示例3: rowCount

# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QModelIndex [as 别名]
def rowCount(self, parent=QtCore.QModelIndex()):
                '''The number of rows under the given parent.

                When the parent is valid it means that rowCount is returning
                the number of children of parent.

                Args:
                    parent (:obj:`QtCore.QModelIndex`, optional): Parent

                Returns:
                    int: Number of rows
                '''
                if None == self._data:
                    return 0

                return len(self._data) 
开发者ID:vrtadmin,项目名称:FIRST-plugin-ida,代码行数:18,代码来源:first.py

示例4: index

# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QModelIndex [as 别名]
def index(self, row, column, parent):
        """Returns QModelIndex to row, column in parent (QModelIndex)"""
        if parent.isValid() and parent.column() != 0:
            return QtCore.QModelIndex()

        if parent.isValid():
            parent_pointer = parent.internalPointer()
            parent_dict = self.root[parent_pointer]
        else:
            parent_dict = self.root
            parent_pointer = ()
        row_key = list(parent_dict.keys())[row]
        child_pointer = (*parent_pointer, row_key)
        try:
            child_pointer = self.my_index[child_pointer]
        except KeyError:
            self.my_index[child_pointer] = child_pointer
        index = self.createIndex(row, column, child_pointer)
        return index 
开发者ID:benhoff,项目名称:CHATIMUSMAXIMUS,代码行数:21,代码来源:settings_model.py

示例5: parent

# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QModelIndex [as 别名]
def parent(self, index):
        """
        Returns the parent (QModelIndex) of the given item (QModelIndex)
        Top level returns QModelIndex()
        """
        if not index.isValid():
            return QtCore.QModelIndex()
        child_key_list = index.internalPointer()
        if child_key_list:
            parent_key_list = child_key_list[:-1]
            if parent_key_list == ((),):
                return QtCore.QModelIndex()
            try:
                parent_key_list = self.my_index[parent_key_list]
            except KeyError:
                self.my_index[parent_key_list] = parent_key_list
            return self.createIndex(self.get_row(parent_key_list), 0,
                                    parent_key_list)

        else:
            return QtCore.QModelIndex() 
开发者ID:benhoff,项目名称:CHATIMUSMAXIMUS,代码行数:23,代码来源:settings_model.py

示例6: open_local_file

# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QModelIndex [as 别名]
def open_local_file(self, idx):
        assert isinstance(idx, QModelIndex)
        model = self.localFilesTreeView.model()
        assert isinstance(model, QFileSystemModel)

        if model.isDir(idx):
            return

        local_path = model.filePath(idx)
        remote_path = local_path.rsplit("/", 1)[1]

        if Settings().external_editor_path:
            self.open_external_editor(local_path)
        else:
            if FileInfo.is_file_binary(local_path):
                QMessageBox.information(self, "Binary file detected", "Editor doesn't support binary files.")
                return
            with open(local_path) as f:
                text = "".join(f.readlines())
                self.open_code_editor()
                self._code_editor.set_code(local_path, remote_path, text) 
开发者ID:BetaRavener,项目名称:uPyLoader,代码行数:23,代码来源:main_window.py

示例7: insertObjects

# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QModelIndex [as 别名]
def insertObjects(self, i, num = 1):
        if ((len(self.objects) == 0) and (self.templateObject is None)) or (num <= 0):
            return False
        i = min([max([0, i]), len(self.objects)])  # Clamp i to within [0, # of objects].
        if self.isRowObjects:
            self.beginInsertRows(QModelIndex(), i, i + num - 1)
        else:
            self.beginInsertColumns(QModelIndex(), i, i + num - 1)
        for objectIndex in range(i, i + num):
            if self.templateObject is not None:
                self.objects.insert(objectIndex, copy.deepcopy(self.templateObject))
            elif len(self.objects):
                copyIndex = min([max([0, objectIndex]), len(self.objects) - 1])  # Clamp objectIndex to a valid object index.
                self.objects.insert(objectIndex, copy.deepcopy(self.objects[copyIndex]))
        if self.isRowObjects:
            self.endInsertRows()
        else:
            self.endInsertColumns()
        return True 
开发者ID:aseylys,项目名称:KStock,代码行数:21,代码来源:ObjList.py

示例8: removeObjects

# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QModelIndex [as 别名]
def removeObjects(self, i, num = 1):
        if (len(self.objects) == 0) or (num <= 0):
            return False
        i = min([max([0, i]), len(self.objects) - 1])  # Clamp i to a valid object index.
        num = min([num, len(self.objects) - i])  # Clamp num to a valid number of objects.
        if num == len(self.objects):
            # Make sure we have a template for inserting objects later.
            if self.templateObject is None:
                self.templateObject = self.objects[0]
        if self.isRowObjects:
            self.beginRemoveRows(QModelIndex(), i, i + num - 1)
            del self.objects[i:i+num]
            self.endRemoveRows()
        else:
            self.beginRemoveColumns(QModelIndex(), i, i + num - 1)
            del self.objects[i:i+num]
            self.endRemoveColumns()
        return True 
开发者ID:aseylys,项目名称:KStock,代码行数:20,代码来源:ObjList.py

示例9: index

# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QModelIndex [as 别名]
def index(self, row, column, parent=None, *args, **kwargs):
        try:
            if not parent or not parent.isValid():
                if 0 <= row < len(self.accounts):
                    return self.createIndex(row, column, self.accounts[row])
                else:
                    return QModelIndex()
            parentNode = parent.internalPointer()
            if isinstance(parentNode, Bip44AccountType):
                addr = parentNode.address_by_index(row)
                if addr:
                    return self.createIndex(row, column, addr)
            return QModelIndex()
        except Exception as e:
            log.exception('Exception while creating index')
            raise 
开发者ID:Bertrand256,项目名称:dash-masternode-tool,代码行数:18,代码来源:wallet_data_models.py

示例10: ecuSel

# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QModelIndex [as 别名]
def ecuSel(self, index):
        if index.parent() == core.QModelIndex():
            return
        item = self.list.model().itemData(self.list.model().index(index.row(), 0, index.parent()))
        if qt5:
            selected = item[0]
        else:
            selected = utf8(item[0].toString())
        target = self.ecuscan.ecu_database.getTarget(selected)
        name = selected
        if target:
            self.ecuscan.addTarget(target)
            if target.addr in self.ecuscan.ecu_database.addr_group_mapping:
                group = self.ecuscan.ecu_database.addr_group_mapping[target.addr]
            else:
                group = "Unknown"
            print name, group
            name = "[ " + group + " ] " + name
        if selected:
            if name not in options.main_window.ecunamemap:
                options.main_window.ecunamemap[name] = selected
                self.treeview_ecu.addItem(name) 
开发者ID:cedricp,项目名称:ddt4all,代码行数:24,代码来源:ddt4all.py

示例11: __init__

# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QModelIndex [as 别名]
def __init__(self, parent, idx, *args, **kwargs):
            QtGui.QMenu.__init__(self, *args, **kwargs)
            self.parent = parent
            self.sandbox = parent.sandbox
            self.idx = idx

            def removeSource():
                self.sandbox.sources.removeSource(self.idx)

            editAction = self.addAction(
                'Edit', lambda: self.parent.editSource(self.idx))

            self.addMenu(
                SourcesAddButton.SourcesAddMenu(self.sandbox, self))
            self.addSeparator()

            removeAction = self.addAction(
                self.style().standardIcon(
                    QtGui.QStyle.SP_DialogCloseButton),
                'Remove', removeSource)

            if self.sandbox.sources.rowCount(QtCore.QModelIndex()) == 0:
                editAction.setEnabled(False)
                removeAction.setEnabled(False) 
开发者ID:pyrocko,项目名称:kite,代码行数:26,代码来源:sources_dock.py

示例12: parent

# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QModelIndex [as 别名]
def parent(self, child):
        if not self._container:
            return QModelIndex()

        if not child.isValid():
            return QModelIndex()

        parent = child.internalPointer().parent
        if not parent:
            return QModelIndex()

        row = None
        if not parent.parent:
            row = self._container.definitions.index(parent)
        else:
            row = parent.parent.children.index(parent)

        return self.createIndex(row, 0, parent) 
开发者ID:Ultimaker,项目名称:Uranium,代码行数:20,代码来源:DefinitionTreeModel.py

示例13: __init__

# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QModelIndex [as 别名]
def __init__(self, parent=None, win=None, xrefs=None, headers=None):
        super(XrefValueWindow, self).__init__(parent)
        self.parent = parent
        self.mainwin = win
        self.xrefs = xrefs
        self.headers = headers

        self.reverse_strings = {}

        self.proxyModel = QtCore.QSortFilterProxyModel()
        self.proxyModel.setDynamicSortFilter(True)

        self.model = QtGui.QStandardItemModel(len(self.xrefs),
                                              len(self.headers), self)

        column = 0
        for header in headers:
            self.model.setHeaderData(column, QtCore.Qt.Horizontal, header)
            column += 1

        row = 0
        for ref in xrefs:
            for column in range(len(self.headers)):
                self.model.setData(self.model.index(
                    row, column, QtCore.QModelIndex()), "%s" % ref[column])
            row += 1

        self.proxyModel.setSourceModel(self.model)

        self.setRootIsDecorated(False)
        self.setAlternatingRowColors(True)
        self.setModel(self.proxyModel)
        self.setSortingEnabled(True)
        self.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)

        self.doubleClicked.connect(self.slotDoubleClicked) 
开发者ID:amimo,项目名称:dcc,代码行数:38,代码来源:xrefwindow.py

示例14: test_delete_cur_item_no_cat

# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QModelIndex [as 别名]
def test_delete_cur_item_no_cat():
    """Test completion_item_del with no selected category."""
    callback = mock.Mock(spec=[])
    model = completionmodel.CompletionModel()
    model.rowsAboutToBeRemoved.connect(callback)
    model.rowsRemoved.connect(callback)
    with pytest.raises(qtutils.QtValueError):
        model.delete_cur_item(QModelIndex())
    callback.assert_not_called() 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:11,代码来源:test_completionmodel.py

示例15: _cat_from_idx

# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QModelIndex [as 别名]
def _cat_from_idx(self, index):
        """Return the category pointed to by the given index.

        Args:
            idx: A QModelIndex
        Returns:
            A category if the index points at one, else None
        """
        # items hold an index to the parent category in their internalPointer
        # categories have an empty internalPointer
        if index.isValid() and not index.internalPointer():
            return self._categories[index.row()]
        return None 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:15,代码来源:completionmodel.py


注:本文中的PyQt5.QtCore.QModelIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。