[Python] In PySide6 how to set the QTableView cell font color when in edit mode?

Discussão em 'Python' iniciado por Stack, Setembro 3, 2025.

  1. Stack

    Stack Membro Participativo

    I created a PySide6 application with a QTableView where the user can edit cells values. The QTableView parent QDialog has a blue background set with stylesheet:

    background-color: #11375E;


    and the QTableView has the stylesheet:

    QHeaderView::section {
    background-color: transparent;
    border-style : hidden
    }


    QTableView cells font color is set to white in model with:

    def data(self, index, role):
    match role:
    case Qt.ItemDataRole.ForegroundRole:
    return QBrush(QColorConstants.White)


    Cells are editable since I set the flags:

    def flags(self, index):
    return Qt.ItemFlag.ItemIsEnabled|Qt.ItemFlag.ItemIsEditable


    With either OS dark or light theme the table correctly appears as:
    [​IMG]

    The problem arises when in edit mode.
    With dark theme the edit font is white:
    [​IMG]
    but with light theme the text is black and barely visible:
    [​IMG]

    I hoped that it was possible to be notified when the cell enters in edit mode, in order to programmatically set the font color, but I have still not found something like that.
    Neither I was able to find a stylesheet property specific for cell font color in edit mode.

    Continue reading...

Compartilhe esta Página