Bre*_*nes 6 icons qt highlighting selected qlistview
在图标模式下使用qlistview时,我需要在选择图标时完全删除hilighting.使用下面的代码不再突出显示图标下方的文本,但选中后仍然会在图标上显示蓝色
QString stylesheet = "";
stylesheet += "QListView::item:alternate {background-image: transparent; background-color: transparent;}";
stylesheet += "QListView::item:selected {background-image: transparent; background-color: transparent;padding: 0px;color: black;}";
stylesheet += "QListView::item:selected:active{background-image: transparent;background-color: transparent; color: black;}";
stylesheet += "QListView::item:selected:!active{background-image: transparent;background-color: transparent;color: black;}";
setStyleSheet(stylesheet);
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何在图标上更改所选颜色而不必继承QStandardItem?
小智 6
对于带有QStandardItem的QListView,它可以做你想要的.只需创建一个图标,为正常状态和选定状态添加相同的像素图.然后在项目中设置setIcon
QIcon icon;
icon.addPixmap(yourPixmap,QIcon::Normal);
icon.addPixmap(yourPixmap,QIcon::Selected);
qstandardItem.setIcon(icon);
Run Code Online (Sandbox Code Playgroud)