Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Change selected row background color in StyledTableItemDelegate
Qt 6.11 is out! See what's new in the release blog

Change selected row background color in StyledTableItemDelegate

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 834 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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);
    

    }@

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved