How to physically deselect a QListWidgetItem under Linux
This may be a question about how to use the Linux UI, not just a Qt issue!
Qt5. Ubuntu 18.04, which uses GNOME desktop if that's relevant.
I have a plain, default
QListWidget, single-selection. It starts life with an item (
QListWidgetItem) selected, shown with dark blue background.
Now, I/my user wants to deselect that item, and have nothing selected. So using my Windows know-how, I go Ctrl+click on the selected item. Its dark-blue background disappears, it now shows with a light-blue background. Maybe indicating "focus", I don't know.
QListWidget::currentRowis still the old selected row, and
QListWidget::currentItemis still there....
Am I doing the wrong key press, assuming it works like Windows? (Tried Googling, no help.) Or, am I misunderstanding, is "current row" != "selected row"?
The current and the selected index are independently from each other. Ctrl+Click imo only deselects the item(s) but does not remove the current index. If you want to reset the current index you have to do call setCurrentIndex(QModelIndex())
That's not at all what I'm trying to achieve. All I'm doing is having a button which acts on whatever the user has "selected" in the UI, by having clicked on it, and it turns dark blue. And the user should be able to "unselect" that by Ctrl+Click. Absolutely standard stuff.
Now, I thought I was supposed to do that by looking at the current item (e.g.
QListWidget::currentRow). I thought that meant the dark blue one.
But from what you're saying, does my/the user's idea of "current" item actually correspond to Qt's selected item instead?
I think yes. The current one is rendered with a small focus rect and can only be exactly one item.
I will re-investigate.
In that case, I think I understand what Qt's "selected" item(s) is(are), what does it (a
QListWidgetat least) use a "current" item for?