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


Python QModelIndex.isValid方法代码示例

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


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

示例1: __newFolder

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import isValid [as 别名]
 def __newFolder(self):
     """
     Private slot to add a new bookmarks folder.
     """
     from .BookmarkNode import BookmarkNode
     
     currentIndex = self.bookmarksTree.currentIndex()
     idx = QModelIndex(currentIndex)
     sourceIndex = self.__proxyModel.mapToSource(idx)
     sourceNode = self.__bookmarksModel.node(sourceIndex)
     row = -1    # append new folder as the last item per default
     
     if sourceNode is not None and \
        sourceNode.type() != BookmarkNode.Folder:
         # If the selected item is not a folder, add a new folder to the
         # parent folder, but directly below the selected item.
         idx = idx.parent()
         row = currentIndex.row() + 1
     
     if not idx.isValid():
         # Select bookmarks menu as default.
         idx = self.__proxyModel.index(1, 0)
     
     idx = self.__proxyModel.mapToSource(idx)
     parent = self.__bookmarksModel.node(idx)
     node = BookmarkNode(BookmarkNode.Folder)
     node.title = self.tr("New Folder")
     self.__bookmarksManager.addBookmark(parent, node, row)
开发者ID:pycom,项目名称:EricShort,代码行数:30,代码来源:BookmarksDialog.py

示例2: setData

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import isValid [as 别名]
    def setData(self, index: QModelIndex, value: QVariant, role: int = None):
        if not index.isValid():
            return False
        item = index.internalPointer()

        if role == Qt.CheckStateRole:
            childrenCount = item.childrenCount()
            if childrenCount:
                for i in range(childrenCount):
                    self.setData(index.child(i, 0), value, role = role)
            else:
                item.selected = bool(value)
            self.dataChanged.emit(index, index, [Qt.CheckStateRole])

            # recalculate parents
            p = index
            while True:
                p = p.parent()
                if p.isValid():
                    self.dataChanged.emit(p, p, [Qt.CheckStateRole])
                else:
                    break

            # success
            return True

        if role == Qt.EditRole:
            assert index.column() == TaskTreeColumn.FileName
            item.setNameByUser(value)
            self.dataChanged.emit(index, index, [Qt.DisplayRole])
            return True

        return False
开发者ID:AbaiQi,项目名称:XwareDesktop,代码行数:35,代码来源:TaskTreeModel.py

示例3: data

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import isValid [as 别名]
    def data(self, index: QModelIndex, role=Qt.DisplayRole):
        if not index.isValid():
            return None

        i = index.row()
        j = index.column()
        device = self.get_device_at(i)
        if role == Qt.DisplayRole:
            if j == 0:
                return self.backend_handler.DEVICE_NAMES[i]
            elif j == 1:
                if device.is_enabled:
                    if device.supports_rx and device.supports_tx:
                        device_info = "supports RX and TX"
                    elif device.supports_rx and not device.supports_tx:
                        device_info = "supports RX only"
                    elif not device.supports_rx and device.supports_tx:
                        device_info = "supports TX only"
                    else:
                        device_info = ""
                else:
                    device_info = "disabled"

                return device_info
            elif j == 2:
                return "" if device.has_native_backend else "not available"
            elif j == 3:
                return "" if device.has_gnuradio_backend else "not available"
        elif role == Qt.CheckStateRole:
            if j == 0 and (device.has_native_backend or device.has_gnuradio_backend):
                return Qt.Checked if device.is_enabled else Qt.Unchecked
            elif j == 2 and device.has_native_backend:
                return Qt.Checked if device.selected_backend == Backends.native else Qt.Unchecked
            elif j == 3 and device.has_gnuradio_backend:
                return Qt.Checked if device.selected_backend == Backends.grc else Qt.Unchecked
开发者ID:jopohl,项目名称:urh,代码行数:37,代码来源:OptionsDialog.py

示例4: getItem

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import isValid [as 别名]
    def getItem(self, index: QModelIndex) -> ProtocolTreeItem:
        if index.isValid():
            item = index.internalPointer()
            if item:
                return item

        return self.rootItem
开发者ID:jopohl,项目名称:urh,代码行数:9,代码来源:ProtocolTreeModel.py

示例5: flags

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import isValid [as 别名]
 def flags(self, index: QModelIndex):
     if index.isValid():
         if self.is_writeable:
             return Qt.ItemIsEnabled | Qt.ItemIsEditable | Qt.ItemIsSelectable
         else:
             return Qt.ItemIsEnabled | Qt.ItemIsSelectable
     else:
         return Qt.NoItemFlags
开发者ID:jopohl,项目名称:urh,代码行数:10,代码来源:SimulatorMessageTableModel.py

示例6: parent

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

        item = index.internalPointer().parent
        if item == self.root or item is None:
            return QtCore.QModelIndex()
        else:
            return self.createIndex(item.row, 0, item)
开发者ID:Orochimarufan,项目名称:comPlex,代码行数:11,代码来源:gui.py

示例7: rowCount

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import isValid [as 别名]
    def rowCount(self, parent: QModelIndex = None, *args, **kwargs):
        if not self._root:
            return 0

        if parent.isValid():
            parentItem = parent.internalPointer()
            return parentItem.childrenCount()
        else:
            return self._root.childrenCount()
开发者ID:AbaiQi,项目名称:XwareDesktop,代码行数:11,代码来源:TaskTreeModel.py

示例8: data

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import isValid [as 别名]
    def data(self, index: QModelIndex, role=Qt.DisplayRole):
        if not index.isValid():
            return None

        i, j = index.row(), index.column()

        try:
            lbl = self.display_labels[i]
        except IndexError:
            return None

        if not lbl or not self.message:
            return None

        if isinstance(lbl, ChecksumLabel):
            calculated_crc = lbl.calculate_checksum_for_message(self.message, use_decoded_bits=True)
        else:
            calculated_crc = None

        if role == Qt.DisplayRole:
            if j == 0:
                return lbl.name
            elif j == 1:
                return lbl.DISPLAY_FORMATS[lbl.display_format_index]
            elif j == 2:
                start, end = self.message.get_label_range(lbl, lbl.display_format_index % 3, True)
                if lbl.display_format_index in (0, 1, 2):
                    try:
                        data = self.bit_str[self.message_index][start:end] if lbl.display_format_index == 0 \
                            else self.hex_str[self.message_index][start:end] if lbl.display_format_index == 1 \
                            else self.ascii_str[self.message_index][start:end] if lbl.display_format_index == 2 \
                            else ""
                    except IndexError:
                        return None
                else:
                    # decimal
                    try:
                        data = str(int(self.bit_str[self.message_index][start:end], 2))
                    except (IndexError, ValueError):
                        return None

                if calculated_crc is not None:
                    data += " (should be {0})".format(util.convert_bits_to_string(calculated_crc, lbl.display_format_index))

                return data

        elif role == Qt.BackgroundColorRole:
            if isinstance(lbl, ChecksumLabel):
                start, end = self.message.get_label_range(lbl, 0, True)
                if calculated_crc == self.message.decoded_bits[start:end]:
                    return constants.BG_COLOR_CORRECT
                else:
                    return constants.BG_COLOR_WRONG

            else:
                return None
开发者ID:Cyber-Forensic,项目名称:urh,代码行数:58,代码来源:LabelValueTableModel.py

示例9: data

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import isValid [as 别名]
 def data(self, index: QtCore.QModelIndex, role=QtCore.Qt.DisplayRole):
     if index.isValid():
         ip = index.internalPointer()
         if index.column() == 0:
             if role == QtCore.Qt.DisplayRole:
                 return ("*" if ip.unfinished() else "") + ip.title()
             elif role == QtCore.Qt.ToolTipRole:
                 return ip.tooltip()
             elif role == QtCore.Qt.DecorationRole:
                 return ip.image()
开发者ID:Orochimarufan,项目名称:comPlex,代码行数:12,代码来源:gui.py

示例10: parent

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

        childItem = index.internalPointer()
        parentItem = childItem.parent

        if parentItem == self._root:
            return QModelIndex()
        else:
            return self.createIndex(parentItem.siblingNumber(), 0, parentItem)
开发者ID:Benyjuice,项目名称:XwareDesktop,代码行数:13,代码来源:TaskTreeModel.py

示例11: data

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import isValid [as 别名]
    def data(self, index: QModelIndex, role=Qt.DisplayRole):
        i = index.row()
        participant = self.simulator_config.active_participants[i]

        if not index.isValid():
            return None

        if role == Qt.DisplayRole:
            return participant.name + " (" + participant.shortname + ")"
        elif role == Qt.CheckStateRole:
            return Qt.Checked if participant.simulate else Qt.Unchecked
开发者ID:jopohl,项目名称:urh,代码行数:13,代码来源:SimulatorParticipantListModel.py

示例12: flags

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import isValid [as 别名]
 def flags(self, index: QtCore.QModelIndex) -> QtCore.Qt.ItemFlags:
     flags = super().flags(index)
     if not index.isValid():
         return flags
     flags |= QtCore.Qt.ItemIsDragEnabled
     file_item = self.item(index)
     if index.column() == 0:
         flags |= QtCore.Qt.ItemIsEditable
         if file_item.is_dir:
             flags |= QtCore.Qt.ItemIsDropEnabled
     return flags
开发者ID:Gebon,项目名称:FTP_client,代码行数:13,代码来源:remote_filesystem_model.py

示例13: tilesChanged

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import isValid [as 别名]
    def tilesChanged(self, tiles):
        if (tiles.first().tileset() != self.mTileset):
            return
        topLeft = QModelIndex()
        bottomRight = QModelIndex()
        for tile in tiles:
            i = self.tileIndex(tile)
            if (not topLeft.isValid()):
                topLeft = i
                bottomRight = i
                continue

            if (i.row() < topLeft.row() or i.column() < topLeft.column()):
                topLeft = self.index(min(topLeft.row(), i.row()),
                                min(topLeft.column(), i.column()))
            if (i.row() > bottomRight.row() or i.column() > bottomRight.column()):
                bottomRight = self.index(max(bottomRight.row(), i.row()),
                                    max(bottomRight.column(), i.column()))

        if (topLeft.isValid()):
            self.dataChanged.emit(topLeft, bottomRight)
开发者ID:theall,项目名称:Python-Tiled,代码行数:23,代码来源:tilesetmodel.py

示例14: data

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import isValid [as 别名]
 def data(self, index: QModelIndex,
          role: int = Qt.DisplayRole) -> Optional[str]:
     """Qt override."""
     if index.isValid() and role == Qt.DisplayRole:
         obj = self.listdata[index.row()]
         colname = self.header_attr[index.column()]
         thing = getattr(obj, colname)
         if callable(thing):
             return str(thing())
         else:
             return str(thing)
     return None
开发者ID:RudolfCardinal,项目名称:whisker-python-client,代码行数:14,代码来源:qt.py

示例15: data

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import isValid [as 别名]
    def data(self, index: QModelIndex, role=Qt.DisplayRole):
        if not index.isValid():
            return None

        i = index.row()
        j = index.column()

        if role == Qt.DisplayRole and self.display_data:
            if self.label_mask[i, j]:
                return "."

        return super().data(index, role)
开发者ID:jopohl,项目名称:urh,代码行数:14,代码来源:SimulatorMessageTableModel.py


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