0
votes

I have a window which displays tiles, each tile having some set of information. Tiles are arranged in a tabular structure. The way in which this is implemented is, a QListWidget is used to hold tiles and each tile is set as the item widget in QListWidgetItems in QListWidget.

I have styled the tiles using a stylesheet. My problem is, I cannot get a tile highlighted in some way when the tile is selected. If I do not use stylesheets at all, default selected highlighting works. But as soon as I apply styles to tiles, there is no difference in the tile in non selected and selected states.

I tried to do it in following way but it does not work.

.tile
{
/*non selected style*/
}

.tileList::item:selected
.tile
{
/*selected style*/
}

Any idea how I can achieve this?

2

2 Answers

1
votes

I solved it in Qt Designer by setting the palette how I wanted it and then put

QListView::item:selected { background: palette(Highlight) }

as the styleSheet. Maybe this helps somebody.

If you want to do it from a central qss, I guess you'll have to remove the ".tile" part from the code in the question.

.tileList::item:selected
.tile <--- remove this line
{
/*selected style*/
}
1
votes

I could get this done to some extent (not a comprehensive solution), by doing following.

  1. Make tile widget semi transparent.
  2. Set a background color to QListWidgetItem
  3. Set a different background color to QListWidgetItem when selected

Styles:

.titleList::item {
    background-color: #fff;
}

.lstSnapQuote::item:selected {
    background-color: #5555FF;
}