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


Python QtCore.QModelIndex类代码示例

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


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

示例1: data

    def data(self, QModelIndex, int_role=None):
        result_couple = self.cmp_res.result_l[QModelIndex.row()]

        if int_role == Qt.DisplayRole:
            if QModelIndex.column() == ResultTableMdl.NAME_COLUMN:
                return result_couple.test_var.name
            if QModelIndex.column() == ResultTableMdl.ERROR_COLUMN:
                return '{:.3f}%'.format(result_couple.error)
            if QModelIndex.column() == ResultTableMdl.STATUS_COLUMN:
                return result_couple.status

        if int_role == Qt.ForegroundRole and QModelIndex.column() == ResultTableMdl.STATUS_COLUMN:
            color = QBrush(Qt.black)
            if result_couple.status == ResultCouple.STS_KO:
                #RED
                color = QBrush(Qt.red)
            if result_couple.status == ResultCouple.STS_WARN:
                #YELLOW
                color = QBrush(QColor(255, 157, 0, 255))
            if result_couple.status == ResultCouple.STS_PASS:
                # Yellowish-GREEN
                color = QBrush(QColor(153, 204, 0, 255))
            if result_couple.status == ResultCouple.STS_MATCH:
                # GREEN
                color = QBrush(QColor(0, 204, 0, 255))
            return color
开发者ID:cerealito,项目名称:validate,代码行数:26,代码来源:ResultTableMdl.py

示例2: getItem

    def getItem(self, index: QModelIndex) -> ProtocolTreeItem:
        if index.isValid():
            item = index.internalPointer()
            if item:
                return item

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

示例3: data

 def data(self, index: QModelIndex, role=Qt.DisplayRole):
     i, j = index.row(), index.column()
     if role == Qt.DisplayRole:
         try:
             lbl = self.message_type[i]
         except IndexError:
             return False
         if j == 0:
             return lbl.name
         elif j == 1:
             return self.message.get_label_range(lbl, view=self.proto_view, decode=True)[0] + 1
         elif j == 2:
             return self.message.get_label_range(lbl, view=self.proto_view, decode=True)[1]
         elif j == 3:
             return lbl.color_index
         elif j == 4:
             return lbl.apply_decoding
     elif role == Qt.TextAlignmentRole:
         return Qt.AlignCenter
     elif role == Qt.FontRole and j == 0:
         font = QFont()
         font.setItalic(self.message_type[i].field_type is None)
         return font
     else:
         return None
开发者ID:Cyber-Forensic,项目名称:urh,代码行数:25,代码来源:PLabelTableModel.py

示例4: __newFolder

 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,代码行数:28,代码来源:BookmarksDialog.py

示例5: setData

    def setData(self, index: QModelIndex, value, role=Qt.DisplayRole):
        if role != Qt.EditRole:
            return True

        i = index.row()
        j = index.column()
        a = self.get_alignment_offset_at(i)
        j -= a
        hex_chars = ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f")

        if i >= len(self.protocol.messages):
            return False

        if self.proto_view == 0 and value in ("0", "1") and self.__pad_until_index(i, j + 1):
            self.protocol.messages[i][j] = bool(int(value))
            self.display_data[i][j] = int(value)
        elif self.proto_view == 1 and value in hex_chars and self.__pad_until_index(i, (j + 1) * 4):
            converted_j = self.protocol.convert_index(j, 1, 0, self.decode, message_indx=i)[0]
            bits = "{0:04b}".format(int(value, 16))
            for k in range(4):
                self.protocol.messages[i][converted_j + k] = bool(int(bits[k]))
            self.display_data[i][j] = int(value, 16)
        elif self.proto_view == 2 and len(value) == 1 and self.__pad_until_index(i, (j + 1) * 8):
            converted_j = self.protocol.convert_index(j, 2, 0, self.decode, message_indx=i)[0]
            bits = "{0:08b}".format(ord(value))
            for k in range(8):
                self.protocol.messages[i][converted_j + k] = bool(int(bits[k]))
            self.display_data[i][j] = ord(value)
        else:
            return False

        self.data_edited.emit(i, j)
        return True
开发者ID:jopohl,项目名称:urh,代码行数:33,代码来源:TableModel.py

示例6: data

    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,代码行数:35,代码来源:OptionsDialog.py

示例7: setData

    def setData(self, index: QModelIndex, value, role=Qt.EditRole):
        if value == "":
            return True

        i = index.row()
        j = index.column()
        if i >= len(self.message_type):
            return False

        lbl = self.__get_label_at(i)

        if j == 0:
            lbl.name = value
            type_before = type(lbl)
            self.message_type.change_field_type_of_label(lbl, self.field_types_by_caption.get(value, None))

            lbl = self.__get_label_at(i)

            if type_before != ProtocolLabel or type(lbl) != ProtocolLabel:
                self.special_status_label_changed.emit(lbl)

        elif j == 1:
            lbl.start = self.message.convert_index(int(value - 1), from_view=self.proto_view, to_view=0, decoded=True)[
                0]
        elif j == 2:
            lbl.end = self.message.convert_index(int(value), from_view=self.proto_view, to_view=0, decoded=True)[0]
        elif j == 3:
            lbl.color_index = value
        elif j == 4:
            if bool(value) != lbl.apply_decoding:
                lbl.apply_decoding = bool(value)
                self.apply_decoding_changed.emit(lbl)

        return True
开发者ID:jopohl,项目名称:urh,代码行数:34,代码来源:PLabelTableModel.py

示例8: setData

    def setData(self, index: QModelIndex, value, role=None):
        if role == Qt.EditRole:
            i, j = index.row(), index.column()
            label = self.message_type[i]  # type: SimulatorProtocolLabel

            if j == 0:
                label.name = value
                ft = self.controller.field_types_by_caption.get(value, FieldType("Custom", FieldType.Function.CUSTOM))
                label.field_type = ft
            elif j == 1:
                label.display_format_index = value
            elif j == 2:
                label.value_type_index = value
            elif j == 3:
                if label.value_type_index == 0:
                    message = label.parent()
                    try:
                        bits = util.convert_string_to_bits(value, label.display_format_index,
                                                           target_num_bits=label.end-label.start)

                        message.plain_bits[label.start:label.end] = bits
                    except ValueError:
                        pass
                elif label.value_type_index == 2:
                    label.formula = value
                elif label.value_type_index == 3:
                    label.external_program = value
                elif label.value_type_index == 4:
                    label.random_min = value[0]
                    label.random_max = value[1]
            self.dataChanged.emit(self.index(i, 0),
                                  self.index(i, self.columnCount()))
            self.protocol_label_updated.emit(label)

        return True
开发者ID:jopohl,项目名称:urh,代码行数:35,代码来源:SimulatorMessageFieldModel.py

示例9: setData

    def setData(self, index: QModelIndex, value, role=Qt.DisplayRole):
        i = index.row()
        j = index.column()
        if i >= len(self.participants):
            return False

        participant = self.participants[i]

        if j == 0:
            participant.name = value
        elif j == 1:
            participant.shortname = value
        elif j == 2:
            participant.color_index = int(value)
        elif j == 3:
            for other in self.participants:
                if other.relative_rssi == int(value):
                    other.relative_rssi = participant.relative_rssi
                    break
            participant.relative_rssi = int(value)
        elif j == 4:
            participant.address_hex = value

        self.update()
        self.participant_edited.emit()

        return True
开发者ID:jopohl,项目名称:urh,代码行数:27,代码来源:ParticipantTableModel.py

示例10: setData

    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,代码行数:33,代码来源:TaskTreeModel.py

示例11: link_index

 def link_index(self, index: QModelIndex):
     try:
         lbl = self.message_type[index.row()]  # type: SimulatorProtocolLabel
         if index.column() == 2 and lbl.is_checksum_label:
             return True
     except:
         return False
     return False
开发者ID:jopohl,项目名称:urh,代码行数:8,代码来源:SimulatorMessageFieldModel.py

示例12: flags

    def flags(self, index: QModelIndex):
        flags = super().flags(index)
        if index.column() in (0, 1, 2, 3):
            flags |= Qt.ItemIsEditable
        if index.column() == 0:
            flags |= Qt.ItemIsUserCheckable

        return flags
开发者ID:jopohl,项目名称:urh,代码行数:8,代码来源:LabelValueTableModel.py

示例13: on_commitData

 def on_commitData(editor: QLineEdit):
     new_text = editor.text()
     idx = QModelIndex(self.opened)
     row, col = idx.row(), idx.column()
     _prior_text, user_role = self.tv.text_txid_from_coordinate(row, col)
     # check that we didn't forget to set UserRole on an editable field
     assert user_role is not None, (row, col)
     self.tv.on_edited(idx, user_role, new_text)
开发者ID:faircoin,项目名称:electrumfair,代码行数:8,代码来源:util.py

示例14: flags

    def flags(self, index: QModelIndex):
        result = Qt.ItemIsEnabled | Qt.ItemIsSelectable
        if index.column() == TaskTreeColumn.FileName:
            result |= Qt.ItemIsUserCheckable | Qt.ItemIsTristate
            if index.row() == 0:
                result |= Qt.ItemIsEditable

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

示例15: setData

 def setData(self, index: QModelIndex, value, role=Qt.DisplayRole):
     if role == Qt.CheckStateRole:
         proto_label = self.labels[index.row()]
         proto_label.fuzz_me = value
         self.protolabel_fuzzing_status_changed.emit(proto_label)
     elif role == Qt.EditRole:
         if len(value) > 0:
             self.labels[index.row()].name = value
     return True
开发者ID:Cyber-Forensic,项目名称:urh,代码行数:9,代码来源:GeneratorListModel.py


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