previously selected item in QListView retains light blue background as long as mouse is over app
-
After adding and selecting a new item in a QListView, the new item receives dark blue background as it should, but the background of the previously selected item goes from dark blue to light blue whereas I need and expect it to go to white. Remarkably, it does go to white if the mouse pointer is taken away from the Qt app (which prevents me from taking a screenshot).
To add and select the new item, I do in the model
beginInsertRows({}, row, row); // append new item to list model endInsertRows(); emit ListChanged();
and in the list view constructor, I did something like
connect(model, &Model::ListChanged, [this] { selectionModel()->clearSelection(); selectionModel()->select(model->index(model->currentIndex(), 0), QItemSelectionModel::Select); });
It all works except for the weird light blue background. I have no clue where it originates.
I removed my entire stylesheet - the dark and light blue backgrounds stay.
-
@Joachim-W It's probably the highlight of the current item. Yes, current item and selection are not the same thing. Try adding
QItemSelectionModel::Current
to your select call to also change the current item.
Also, you don't need to separate clearing and selection, you can just useQItemSelectionModel::ClearAndSelect
to do both in one call. -
-
-