Python PyQt5.QtCore.Qt.ForegroundRole() Examples

The following are 6 code examples of PyQt5.QtCore.Qt.ForegroundRole(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PyQt5.QtCore.Qt , or try the search function .
Example #1
Source File: diff_result.py    From vorta with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #2
Source File: wallet_data_models.py    From dash-masternode-tool with MIT License 5 votes vote down vote up
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]) 
Example #3
Source File: ListModel.py    From DownloaderForReddit with GNU General Public License v3.0 5 votes vote down vote up
def data(self, index, role=Qt.DisplayRole):
        if role == Qt.DisplayRole:
            return self.reddit_object_list[index.row()].name
        elif role == Qt.ForegroundRole:
            if not self.reddit_object_list[index.row()].enable_download:
                return QColor(255, 0, 0, 255)  # set name text to red if download is disabled
            else:
                return None
        elif role == Qt.DecorationRole:
            return None
        elif role == Qt.ToolTipRole:
            return self.set_tooltips(self.reddit_object_list[index.row()])
        elif role == Qt.EditRole:
            return self.reddit_object_list[index.row()].name 
Example #4
Source File: qtmodels.py    From QualCoder with MIT License 5 votes vote down vote up
def data(self,index,role):
        idx = index.row()
        if role == Qt.DisplayRole:
            return self.nativedata[idx][self.key]
        elif role == Qt.ForegroundRole:
            return QtGui.QBrush(Qt.black)
        elif role == Qt.BackgroundRole:
            return QtGui.QBrush(QtGui.QColor(self.nativedata[idx].get('color',Qt.white)))
        elif role == Qt.CheckStateRole:
            return self._checkstate.get(key,Qt.CheckState.Unchecked) 
Example #5
Source File: qtmodels.py    From QualCoder with MIT License 5 votes vote down vote up
def data(self,index,role):
        if index.isValid():
            key = self._row_to_key[index.row()]
            if role == Qt.DisplayRole:
                if self.key is None:
                    return key
                else:
                    return self.nativedata[key][self.key]
            elif role == Qt.ForegroundRole:
                return QtGui.QBrush(Qt.black)
            elif role == Qt.BackgroundRole:
                return QtGui.QBrush(QtGui.QColor(self.nativedata[key].get('color',Qt.white)))
            elif role == Qt.CheckStateRole:
                return self._checkstate.get(key,Qt.CheckState.Unchecked) 
Example #6
Source File: wallet_data_models.py    From dash-masternode-tool with MIT License 4 votes vote down vote up
def data(self, index, role=None):
        if index.isValid():
            col_idx = index.column()
            row_idx = index.row()
            if row_idx < len(self.utxos):
                utxo = self.utxos[row_idx]
                if utxo:
                    if role in (Qt.DisplayRole, Qt.EditRole):
                        col = self.col_by_index(col_idx)
                        if col:
                            field_name = col.name
                            if field_name == 'satoshis':
                                return app_utils.to_string(round(utxo.satoshis / 1e8, 8))
                            elif field_name == 'masternode':
                                if utxo.masternode:
                                    return utxo.masternode.name
                            elif field_name == 'confirmations':
                                if utxo.block_height >= UNCONFIRMED_TX_BLOCK_HEIGHT:
                                    return 'Unconfirmed'
                                else:
                                    return app_utils.to_string(utxo.__getattribute__(field_name))
                            elif field_name == 'address':
                                if utxo.address_obj and utxo.address_obj.label:
                                    return utxo.address_obj.label
                                else:
                                    return utxo.address
                            elif col.name == 'txid':
                                if self.tx_explorer_url:
                                    url = self.tx_explorer_url.replace('%TXID%', utxo.txid)
                                    url = f'<a href="{url}">{utxo.txid}</a>'
                                    return url
                                else:
                                    return utxo.txid
                            else:
                                return app_utils.to_string(utxo.__getattribute__(field_name))
                    elif role == Qt.ForegroundRole:
                        if utxo.is_collateral:
                            return QColor(Qt.white)
                        elif utxo.coinbase_locked or utxo.block_height >= UNCONFIRMED_TX_BLOCK_HEIGHT:
                            return QColor('red')

                    elif role == Qt.BackgroundRole:
                        if utxo.is_collateral:
                            return QColor(Qt.red)

                    elif role == Qt.TextAlignmentRole:
                        col = self.col_by_index(col_idx)
                        if col:
                            if col.name in ('satoshis', 'confirmations', 'output_index'):
                                return Qt.AlignRight

        return QVariant()