Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一些带有不同文本颜色的项目的 qListWidget。我想在不触摸文本颜色的情况下更改所选项目的背景颜色。我尝试使用 styleSheet,但所有选定的项目都具有相同的颜色。可以在不改变文本颜色的情况下选择项目吗?
尝试使用item->setData(Qt::BackgroundRole, QBrush(color));.
item->setData(Qt::BackgroundRole, QBrush(color));
如果您使用的是 Qt 设计器,请转到您想要此行为的 QListWidget 的属性(属性编辑器)。转到“调色板”,然后单击“更改调色板”。然后将“突出显示的文本”颜色更改为与非突出显示文本相同的颜色。
选择项目时,项目的文本颜色仍在变化,但会变为相同的颜色,因此看起来好像没有变化。
为了您的方便,我附上了一张照片。