Reputation: 1367
In general I need to disable highlighting the QListWidget when user selects the item or widget receives the focus. But I think, that should be a common method for all widgets to do this.
Upvotes: 3
Views: 4010
Reputation: 61
If you mean highlight of (whole) QListView Widget, you may change this property in forms editor or set this in code:
listWidget->setFocusPolicy(Qt::NoFocus);
Upvotes: 1
Reputation: 32635
You can set the palette for Highlight
and HighlightedText
roles. Just set the Highlight
color of the widget to Base
and HighlightedText
to Text
:
QPalette palette;
palette.setColor(QPalette::Highlight, listWidget->palette().color(QPalette::Base));
palette.setColor(QPalette::HighlightedText, listWidget->palette().color(QPalette::Text));
listWidget->setPalette(palette);
Upvotes: 1
Reputation: 21220
Alternatively you can do the following:
QListWidget lw;
[..]
QPalette p = lw.palette();
QColor bgColor = p.color(QPalette::Window);
QColor fgColor = p.color(QPalette::Text);
// Set the item selection color to be the background color of the list widget.
lw.setStyleSheet(QString("QListWidget:item:selected:active { background: %1;} "
"QListWidget:item:selected:active {color: %2; }")
.arg(bgColor.name()).arg(fgColor.name()));
Upvotes: 0