Important: Please read the Qt Code of Conduct -

Get identical signal parameter values when selecting or deselecting an item in a QTreeView

  • I have a QTreeView. If I have a node, with one child, and both that node and its child are selected, I get the same parameters in the selectionChanged signal whether I am selecting OR deselecting the node.

    By which I mean, if I left-click on the node, the QItemSelection parameter in the selectionChanged signal containing the newly selected items is empty, and the selectionChanged signal containing the newly deselected items is not empty (which is NOT what I expected - I clicked one item, I expected the selected list to be that item and the deselected list to be the child).

    if I left-click on it with CTRL held down (which I would expect to be the deselection action), the parameters in the signal are identical. So it seems that it doesn't matter whether the user is left-clicking, or CTRL+left-clicking, the signal parameters are the same. Doesn't matter whther the user is left-clicking on something already selected, or CTRL-left-clicking on it, the signal is identical.

    The selection mode is extended selection. I was expecting the signal parameters to indicate that the item was selected if the action was just left-click, and deselected if the action was CTRL-left-click.

    But it isn't. Same, both ways, but ONLY if I have a node with a single child.

    If I have a node with many children, clicking on the node selects the node and deselects the children (as expected), CTRL-clicking on the node deselects the node and leaves all the children selected (as expected).

    Basically, the behaviour seems wrong ONLY when there is a node with a single child. Is this some kind of bug I've stumbled across? I am using 4.8.something

    ALTERNATIVELY, I'm massively missing the meaning of these parameters, in which case could someone explain them to me in simple terms. I know I've misunderstood them inthe past. I seem to have a real blind spot at this point in the QT documentation, having trouble understanding what they mean to represent with these parameters. Under the old, more useful documentation system, other people had added notes to the documentation to amplify the meaning, but sadly all that useful community-sourced was removed during the revamp.

  • Lifetime Qt Champion


    Can you provide a minimal compilable example that shows that behavior ?

Log in to reply