PDA

View Full Version : Single selection across multiple listsViews



Zicandar
17th May 2016, 13:33
Hello!
I have tired googling this for a while, but been unsuccessful in finding any answer. (Or really anyone asking the same question). What I have found are selection policies and selection modes. But all this is for within a widget.
www.qtcentre.org/threads/57813-Have-a-single-selection-of-item-between-2-QListWidgets does not help me as I will have to many lists. Worst case I can solve it that way, but preferably not.

What I want to achieve is across multiple widgets a single selection across multiple QListViews. So if I select an item in a different list it will deselect all previous items.
What I need is the following:
Across all widgets only a single selection should be shown. I'm using a delegate so relying on focus instead of selection is ok.
If I select an item in a list in a different widget, then when I go back to the item I had previously selected it should give me a callback. (This works if I use selectionChanged + clearing selection on focusOutEvent).

Focus seems like it might be the solution, but also there I have tried to use focusOutEvent and focusInEvent to clear the selection/focus. But I have still not managed to get the result I want. (If I clear selection on focusOutEvent it won't have any selection at all it seems like).

Help would be much appriciated!

anda_skoa
17th May 2016, 16:36
So selecting something in one view should deselect everything in all the other views?
Or should all views then select the same thing?

Cheers,
_

Zicandar
19th May 2016, 08:09
So selecting something in one view should deselect everything in all the other views?
Or should all views then select the same thing?

Cheers,
_

It should "deselect" everything else. Although it doesn't necessarily have to be the selection system. As long as the requirements of being unique within all sub-widgets of a specified widget (or possibly application) and me getting a callback when it's selected.

anda_skoa
19th May 2016, 18:33
You will need a mediator object that knows all QItemSelectionModels and connects to their selectionChanged signal.

When one of the has a selection change, it needs to remember that it is now changing the selection, then deselect all other models, ignore their signals, then restore the normal mode.

Cheers,
_