Python源码示例:PyQt5.QtCore.Qt.DisplayRole()

示例1
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) 
示例2
def headerData(self, section, orientation, role=Qt.DisplayRole):
                '''The data for the given role and section in the header with
                the specified orientation.

                Args:
                    section (:obj:`int`):
                    orientation (:obj:`Qt.Orientation`):
                    role (:obj:`Qt.DisplayRole`):

                Returns:
                    data
                '''
                if role != Qt.DisplayRole:
                    return None

                if (orientation == Qt.Horizontal) and (section < len(self.header)):
                    return self.header[section]

                return None 
示例3
def data(self, index, role = Qt.DisplayRole):
        if not index.isValid():
            return None
        obj = self.getObject(index)
        prop = self.getProperty(index)
        if role == Qt.BackgroundRole:
            return color(obj.D)
        if role == Qt.TextAlignmentRole:
            return Qt.AlignCenter
        if (obj is None) or (prop is None):
            return None
        try:
            if role in [Qt.DisplayRole, Qt.EditRole]:
                return getAttrRecursive(obj, prop['attr'])
        except:
            return None
        return None 
示例4
def createEditor(self, parent, option, index):
        '''
        Return QComboBox with list of choices (either values or their associated keys if they exist).
        '''
        try:
            editor = QComboBox(parent)
            value = index.model().data(index, Qt.DisplayRole)
            for i, choice in enumerate(self.choices):
                if (type(choice) is tuple) and (len(choice) == 2):
                    # choice is a (key, value) tuple.
                    key, val = choice
                    editor.addItem(str(key))  # key MUST be representable as a str.
                    if val == value:
                        editor.setCurrentIndex(i)
                else:
                    # choice is a value.
                    editor.addItem(str(choice))  # choice MUST be representable as a str.
                    if choice == value:
                        editor.setCurrentIndex(i)
            return editor
        except:
            return None 
示例5
def data(self, index, role=None):
        if index.isValid():
            data = index.internalPointer()
            col = index.column()
            if data:
                if role in (Qt.DisplayRole, Qt.EditRole):
                    if col == 0:
                        # if isinstance(data, Bip44AccountType):
                        #     return data.get_account_name()
                        # else:
                        #     return f'/{data.address_index}: {data.address}'
                        return data
                    elif col == 1:
                        b = data.balance
                        if b:
                            b = b/1e8
                        return b
                    elif col == 2:
                        b = data.received
                        if b:
                            b = b/1e8
                        return b
        return QVariant() 
示例6
def data(self, index, role):
        """ Returns the tree item at the given index and role
        """
        if not index.isValid():
            return None

        col = index.column()
        tree_item = index.internalPointer()
        obj = tree_item.obj

        if role == Qt.DisplayRole:
            try:
                attr = self._attr_cols[col].data_fn(tree_item)
                # Replace carriage returns and line feeds with unicode glyphs 
                # so that all table rows fit on one line. 
                #return attr.replace('', unichr(0x240A)).replace('\r', unichr(0x240D))
                return (attr.replace('\r', unichr(0x21B5))
                        .replace('', unichr(0x21B5))
                        .replace('\r', unichr(0x21B5)))
            except StandardError, ex:
                #logger.exception(ex)
                return "**ERROR**: {}".format(ex) 
示例7
def data(self, index, role):
        if not index.isValid():
            return None

        item = index.internalPointer()

        if role == Qt.ForegroundRole:
            if item.itemData[1] == 'removed':
                return QVariant(QColor(Qt.red))
            elif item.itemData[1] == 'added':
                return QVariant(QColor(Qt.green))
            elif item.itemData[1] == 'modified' or item.itemData[1].startswith('['):
                return QVariant(QColor(Qt.darkYellow))

        if role == Qt.DisplayRole:
            return item.data(index.column())
        else:
            return None 
示例8
def data(self, index, role):
        if not index.isValid():
            return None
        node = index.internalPointer()
        if role == Qt.DisplayRole:
            if index.column() == 0:
                return node.name
            elif index.column() == 1:
                return node.capacity
            elif index.column() == 2:
                return node.recoil
            elif index.column() == 3:
                return node.reload
        elif role == Qt.FontRole:
            if index.column() in (1, 2, 3):
                return self.column_font
        return None 
示例9
def data(self, qindex:QModelIndex, role=None):
        if role == Qt.DisplayRole or role == Qt.EditRole:
            entry = self.entries[qindex.row()]
            attr = self.columns[qindex.column()]
            value = getattr(entry, attr)
            if attr in ("gmd_name_index", "gmd_description_index"):
                return get_t9n(self.model, "t9n", value)
            elif attr == "kire_id":
                kire_model = self.model.get_relation_data("kire")
                if kire_model is None:
                    return None
                else:
                    return kire_model.entries[value]
            return value
        elif role == Qt.UserRole:
            entry = self.entries[qindex.row()]
            return entry 
示例10
def data(self, index, role):
        """ Returns the tree item at the given index and role
        """
        if not index.isValid():
            return None

        col = index.column()
        tree_item = index.internalPointer()
        obj = tree_item.obj

        if role == Qt.DisplayRole:
            try:
                attr = self._attr_cols[col].data_fn(tree_item)
                # Replace carriage returns and line feeds with unicode glyphs 
                # so that all table rows fit on one line. 
                #return attr.replace('\n', unichr(0x240A)).replace('\r', unichr(0x240D))
                return (attr.replace('\r\n', unichr(0x21B5))
                            .replace('\n', unichr(0x21B5))
                            .replace('\r', unichr(0x21B5)))
            except StandardError, ex:
                #logger.exception(ex)
                return "**ERROR**: {}".format(ex) 
示例11
def data(self, index, role):
        if not index.isValid():
            return None
        if (index.column() == 0):
            value = self.mylist[index.row()][index.column()].text()
        else:
            value = self.mylist[index.row()][index.column()]
        if role == QtCore.Qt.EditRole:
            return value
            itemSelected.emit()
        elif role == QtCore.Qt.DisplayRole:
            return value
            itemSelected.emit()
        elif role == QtCore.Qt.CheckStateRole:
            if index.column() == 0:
                # print(">>> data() row,col = %d, %d" % (index.row(), index.column()))
                if self.mylist[index.row()][index.column()].isChecked():
                    return QtCore.Qt.Checked
                else:
                    return QtCore.Qt.Unchecked 
示例12
def editCell(self,r,c):
        if c==0:
            nameDialog = NameDialog(self.table.item(r,c))
            name = nameDialog.popUp()
            nameItem = QTableWidgetItem(name)
            self.table.setItem(r,0,nameItem)
            colorItem = QTableWidgetItem()
            colorItem.setData(Qt.DisplayRole, QColor('blue'))
            self.table.setItem(r,1,colorItem)
            if r < len(self.labelHist):
                self.labelHist[r]=name
            else:
                self.labelHist.append(name)
            with open('configGUI/predefined_classes.txt', 'w') as f:
                for item in self.labelHist:
                    f.write("%s\n" % item.text()) 
示例13
def data(self, index, role):
        root = self.get_root_object()
        if role == Qt.DisplayRole or role == Qt.EditRole:
            r = index.row()
            c = index.column()
            eval_str = ('root' + self.colEvalStr[c]).format(r)
            try:
                val = eval(eval_str)
                valStr = self.colFormats[c].format(val)
                return valStr
            except IndexError:
                return ''
            except TypeError:
                print('Data type error: ', eval_str, val)
                return ''
        else:
            return None 
示例14
def data(self, index, role):
        if index.isValid() or (0 <= index.row() < len(self.ListItemData)):
            if role == Qt.DisplayRole:
                return QVariant(self.ListItemData[index.row()]['name'])
            elif role == Qt.DecorationRole:
                return QVariant(QIcon(self.ListItemData[index.row()]['iconPath']))
            elif role == Qt.SizeHintRole:
                return QVariant(QSize(70,80))
            elif role == Qt.TextAlignmentRole:
                return QVariant(int(Qt.AlignHCenter|Qt.AlignVCenter))
            elif role == Qt.FontRole:
                font = QFont()
                font.setPixelSize(20)
                return QVariant(font)
        else:            
            return QVariant() 
示例15
def data(self, index, role=Qt.DisplayRole):
                '''The data stored under the given role for the item referred
                to by the index.

                Args:
                    index (:obj:`QtCore.QModelIndex`): Index
                    role (:obj:`Qt.ItemDataRole`): Default :obj:`Qt.DisplayRole`

                Returns:
                    data
                '''
                if role == Qt.DisplayRole:
                    row = self._data[index.row()]
                    if (index.column() == 0) and (type(row) != dict):
                        return row

                    elif index.column() < self.columnCount():
                        if type(row) == dict:
                            if self.header[index.column()] in row:
                                return row[self.header[index.column()]]
                            elif self.header[index.column()].lower() in row:
                                return row[self.header[index.column()].lower()]

                        return row[index.column()]

                    return None

                elif role == Qt.FontRole:
                    return QtGui.QFont().setPointSize(30)

                elif role == Qt.DecorationRole and index.column() == 0:
                    return None

                elif role == Qt.TextAlignmentRole:
                    return Qt.AlignLeft; 
示例16
def data(self, index, role):
                '''The data stored under the given role for the item referred
                to by the index.

                Args:
                    index (:obj:`QtCore.QModelIndex`): Index
                    role (:obj:`Qt.ItemDataRole`): Default :obj:`Qt.DisplayRole`

                Returns:
                    data
                '''
                if not index.isValid():
                    return None

                #   Color background
                if role == Qt.BackgroundRole:
                    metadata_id = index.data(FIRSTUI.ROLE_ID)
                    address = index.data(FIRSTUI.ROLE_ADDRESS)

                    if (metadata_id and address
                        and ((address, metadata_id) in self.ids_selected)):
                        return FIRST.color_selected

                    elif (metadata_id and address
                          and ((address, metadata_id) in self.applied_ids)):
                        return FIRST.color_applied

                    #   Data has been updated since original
                    elif not metadata_id:
                        return FIRST.color_unchanged

                    #   Return the default color
                    return FIRST.color_default

                return super(FIRST.Model.Check, self).data(index, role) 
示例17
def data(self, index, role):
        """Returns data for given role for given index (QModelIndex)"""
        if not index.isValid():
            return None

        if role != Qt.DisplayRole and role != Qt.EditRole:
            return None

        indexPtr = index.internalPointer()
        if index.column() == 1:    # Column 1, send the value
            return self.root[indexPtr]
        else:                   # Column 0, send the key
            return indexPtr[-1] 
示例18
def data(self, index, role):
        if not index.isValid():
            return None
        elif role != Qt.DisplayRole:
            return None
        return self.arraydata[index.row()][index.column()] 
示例19
def headerData(self, col, orientation, role):
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            return self.headerdata[col]
        return None 
示例20
def headerData(self, section, orientation, role = Qt.DisplayRole):
        if role != Qt.DisplayRole:
            return None
        if ((orientation == Qt.Horizontal) and self.isRowObjects) or ((orientation == Qt.Vertical) and not self.isRowObjects):
            # Display property headers.
            try:
                return self.properties[section]['header']  # Property header.
            except (IndexError, KeyError):
                return None
        else:
            # Display object indices (1-based).
            return (section + 1) if (0 <= section < len(self.objects)) else None 
示例21
def createEditor(self, parent, option, index):
        ''' 
        Return a QLineEdit for arbitrary representation of a float value.
        '''
        editor = QLineEdit(parent)
        value = index.model().data(index, Qt.DisplayRole)
        editor.setText(str(value))
        return editor 
示例22
def createEditor(self, parent, option, index):
        ''' 
        Return a QLineEdit for arbitrary representation of a date value in any format.
        '''
        editor = QLineEdit(parent)
        date = index.model().data(index, Qt.DisplayRole)
        editor.setText(date.strftime(self.format))
        return editor 
示例23
def setModelData(self, editor, model, index):
        ''' 
        Toggle the boolean state in the model.
        '''
        checked = not bool(index.model().data(index, Qt.DisplayRole))
        model.setData(index, checked, Qt.EditRole) 
示例24
def data(self, index, role=None):
        if index.isValid():
            col_idx = index.column()
            row_idx = index.row()
            if row_idx < len(self.mn_items):
                if role in (Qt.DisplayRole, Qt.EditRole):
                    col = self.col_by_index(col_idx)
                    if col:
                        field_name = col.name
                        if field_name == 'description':
                            return self.mn_items[row_idx]
        return QVariant() 
示例25
def set_block_height(self, block_height: int):
        if block_height != self.block_height:
            log.debug('Block height updated to %s', block_height)
            self.block_height = block_height
            # if self.utxos:
            #     tl_index = self.index(0, self.col_index_by_name('confirmations'))
            #     br_index = self.index(len(self.utxos) - 1, self.col_index_by_name('confirmations'))
            #     self.view.dataChanged(tl_index, br_index, [Qt.DisplayRole, Qt.ForegroundRole, Qt.BackgroundColorRole]) 
示例26
def headerData(self, column, orientation, role=Qt.DisplayRole):
        if role == Qt.DisplayRole and orientation == Qt.Vertical:
            idx = self.index(column, 0)
            if idx.isValid():
                idx = self.mapFromSource(idx)
                return str(idx.row() + 1)
        else:
            return ExtSortFilterTableModel.headerData(self, column, orientation, role) 
示例27
def __init__(self, parent=None, readOnly=False, index=True, floatCut=True, autoScroll=True, floatRound=2):
        """
            @index: 是否要插入默认行索引(Org.)
            @floatRound: 小数点后格式化成几位, 只在@floatCut is True时有效
        """
        super().__init__(parent)

        self.setSortingEnabled(True)
        self.verticalHeader().setVisible(False)

        if readOnly:
            self.setEditTriggers(QTableWidget.NoEditTriggers)
            self.setSelectionBehavior(QAbstractItemView.SelectRows) 

        self._role = Qt.DisplayRole if readOnly else Qt.EditRole
        self.__index = index # 原始插入的行索引
        self._floatCut = floatCut
        self._floatRoundFormat = '%.{0}f'.format(floatRound)

        self._autoForegroundCol = None # 指定前景色关键列,如果此列对应的值改变时,将改变所对应行的前景色。包含'Org.'列
        self._enableAutoScroll = autoScroll

        self.setColNames([])

        self._initItemMenu()

        self._initRows() 
示例28
def headerData(self, section, orientation, role):
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            return self._attr_cols[section].name
        else:
            return None 
示例29
def model_updated(self, model):
        config = model.get_config()
        map_names = config.maps_to_show

        with blocked_signals(self.selectedMap):
            current_selected = self.selectedMap.currentData(Qt.UserRole)

            self.selectedMap.clear()
            self.selectedMap.addItems(map_names)

            for index, map_name in enumerate(map_names):
                self.selectedMap.setItemData(index, map_name, Qt.UserRole)

                if map_name in config.map_plot_options and config.map_plot_options[map_name].title:
                    title = config.map_plot_options[map_name].title
                    self.selectedMap.setItemData(index, map_name + ' (' + title + ')', Qt.DisplayRole)

            for ind in range(self.selectedMap.count()):
                if self.selectedMap.itemData(ind, Qt.UserRole) == current_selected:
                    self.selectedMap.setCurrentIndex(ind)
                    break

        if self.selectedMap.count():
            self._update_map_specifics(self.selectedMap.currentData(Qt.UserRole))
        else:
            self._update_map_specifics(None) 
示例30
def headerData(self, section, orientation, role=Qt.DisplayRole):
        if role == Qt.DisplayRole and orientation == Qt.Horizontal:
            return self.HEADER[section]
        return QAbstractTableModel.headerData(self, section, orientation, role)