> 文章列表 > QTableView 设置selection-background-color和border不同时生效问题记录

QTableView 设置selection-background-color和border不同时生效问题记录

QTableView 设置selection-background-color和border不同时生效问题记录

问题:

qtableview在使用过程种设置qss样式,设置选中时的背景色,以及边框颜色,不能同时生效。

解决:

在qss中设置QTableView的样式时,对于item项,selection-background-color的参数设置应该分开写,否则不生效

过程如下:

在tableView中设置选中该行时的背景色,已经在qss中设置了selection-background-color项
 

QTableView::item
{border: 1px groove #DDDDDD ;、selection-background-color: #E8F5FF;            / *选中区域的背景色* /
}

测试一直不生效,背景色设置已经生效或者边框生效,不能同时显示

将两个设置分开写,修改为即可:

        QTableView::item

        {

                border-top:1px solid #DDDDDD ;

                border-bottom-color: #DDDDDD ;

        }

        QTableView::item:selected

        {

                background-color: #E8F5FF;

        }

效果图: