The background color of a certain row or column of QTableView equipment

As the old saying goes, a picture is worth a thousand words

insert image description here

Background: If you just set the background color of QTableView, then there is no need to write this blog. There are many such routines on Baidu. But I encountered a problem in it, that is, it didn’t take effect when I set the background color, but I rebuilt a demo and wrote it again, and it took effect again. point.

原因是我再设置QCombobox样式的时候没有限定导致全局使用了一个样式,覆盖了QTableView的样式,所以无论怎么设置,尝试各种办法,设置背景色的属性都不生效,下面贴导致失败的那个全局样式

QAbstractItemView::item
{
    
    
    background:transparent;
    border-radius:10px;
    padding:6px;
}

下面贴修改后的代码

QComboBox QAbstractItemView::item
{
    
    
    background:transparent;
    border-radius:10px;
    padding:6px;
}

After adding the QComboBox limit, it will be OK immediately, and the QTableView setting background code will not be posted. There are many Baidu, and I hope it can help people who have the same problem as me.

Guess you like

Origin blog.csdn.net/weixin_42485732/article/details/129706175