how to change Qt qListView Icon selection highlight

我只是一个虾纸丫 提交于 2021-02-18 11:17:06

问题


When using qlistview in icon mode I need to completely remove the hilighting when a icon is selected. Using the code below the text under the icon is no longer highlighted but I still get blue color over the icon when selected

 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);

does anyone know how to change the selected color over the icon without having to subclass QStandardItem?


回答1:


For a QListView with QStandardItem's it's possible to do what you want. Simply create an icon an add the same pixmap for both normal and selected states. Then setIcon in the item

QIcon icon;

icon.addPixmap(yourPixmap,QIcon::Normal);
icon.addPixmap(yourPixmap,QIcon::Selected);

qstandardItem.setIcon(icon);



回答2:


Found my own answer. could not remove the section color overlay in QListview without using delegate but after switching to use QListWidget I could disable the selection overlay by setting a selected icon image



来源:https://stackoverflow.com/questions/5044449/how-to-change-qt-qlistview-icon-selection-highlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!