how to change Qt qListView Icon selection highlight
Asked Answered
S

2

8

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?

Sialoid answered 18/2, 2011 at 17:22 Comment(1)
What version of Qt are you using? I am running 4.7.1 and I never see the icon highlighted at all, even without your style sheet.Schizopod
H
13

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);
Hemialgia answered 10/5, 2012 at 13:53 Comment(1)
I've finally found my answer! thx so much! But to remove FocusRect from every other place, this answer worked for me forum.qt.io/topic/87212/how-to-remove-blue-focus-rectangle/2Iona
S
0

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

Sialoid answered 20/2, 2011 at 5:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.