Important: Please read the Qt Code of Conduct -

Change selected row background color in StyledTableItemDelegate

  • Can't change background color of a selected row. Selection is always in default ubuntu style. How can I change this?
    Here is my function paint. As you can see, I try to set the background using this: viewOption.backgroundBrush = QBrush(QColor("#000000"));
    @void StyledTableItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    QPalette pal = option.palette;
    QStyleOptionViewItem viewOption(option);

    if (option.showDecorationSelected && (option.state & QStyle::State_Selected)) {
        viewOption.backgroundBrush = QBrush(QColor("#000000"));
    viewOption.palette.setColor(QPalette::Text, "#6bc74c");
    viewOption.font = QFont("arial", 10);
    if(index.column() == 1) {
        viewOption.displayAlignment = Qt::AlignLeft;
    else if (index.column() == 2) {
        viewOption.displayAlignment = Qt::AlignRight;
    QStyledItemDelegate::paint(painter, viewOption, index);


Log in to reply