本文整理汇总了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)
示例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
示例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
示例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
示例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
示例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)
示例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()
示例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
示例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()
示例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)
示例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
示例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
示例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)
示例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
示例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)