标题:QTableView 如何给各行添加属性
作者:winston_zbb
日期:2021-03-16 15:42
内容:
我想实现QTableView 中不同行背景颜色不同,想到的方法是:通过给QTableView中不同行添加不同属性(setProperty),然后用Qss 实现背景颜色变化。请教下,qt可以实现给表格中的行添加属性(setProperty)么?
#1 [liudianwu 03-16 16:24]
好像不行,不能单独设置,你只能动态识别点了哪一行然后全局设置样式表
#2 [青空飞羽 03-17 09:40]
alternatingRowColors : bool
This property holds whether to draw the background using alternating colors
If this property is true, the item background will be drawn using QPalette::Base and QPalette::AlternateBase; otherwise the background will be drawn using the QPalette::Base color.
By default, this property is false.
Access functions:
bool
alternatingRowColors() const
void
setAlternatingRowColors(bool enable)