PDA

View Full Version : QTreeView parent/child selection behaviors (ghost highlighting)



alketi
1st April 2015, 21:15
I have a QTreeView with parents/children and want to do the following:

1. Only allow the parent of an item to be selected
2. Have the children be unselectable, but allow their checkboxes to be toggled

However -- clicking on a child item does the following two (bad) things:

1. It removes the selection from the parent
2. It leaves some "highlight" mark behind on the child.

Note that I've made the children "unselectable" via model flags, but the two issues above still occur. How can I prevent both of these things from happening?
----------

DESIRED BEHAVIOR

If the user clicks on a child, I want to keep the selection on the Parent uninterrupted (without manually flipping it back to the parent, which causes a "flicker"). And, I don't want the child to get "highlighted" by the translucent selection thing.

Pictures to illustrate:

Normal state. Parent is selected. Children have checkboxes.
11049

Bad behavior. Clicking on 2nd child (that's flagged as unselectable) causes the Parent to lose its selection, and gives the child the ghost selection
11050

Desired. This is what I want to see when I click on a child item -- the checkbox toggles, and the Parent remains selected without interruption.
11051

This must be possible, but I can't find the right combination of settings to get the selections to work as in the 3rd picture.

Any help would be greatly appreciated.

jefftee
2nd April 2015, 21:22
If you are using a custom model, please post your code. If you are using QStandardItemModel have you looked at QStandardItem::setFlags?