0
votes

In my Qt 5.6.2 project, I noticed that if you double click on a QTreeView item (the actual arrow part, not the item text) the first click toggles the expanded state, and the second click does nothing.

I would instead like the second click to again toggle the expanded state.

I tried treeView->setExpandsOnDoubleClick(false); but the behaviour is still the same since it appears to not affect the arrow part of the item at all. It looks like Qt is deciding for me how the arrow should react to a double click regardless of the property expandsOnDoubleClick. How can I resolve this?

(Note: this behaviour didn't exist in Qt 5.0.2. Unsure about intermediate Qt versions.)

1
Honestly if you need a sscce for a simple QTreeView, then it's likely that you won't be able to help. It's just any old QTreeView.mrg95
You say "I would instead like the second click to again toggle the expanded state" -- really? Or do you mean that the first click should do nothing and only the second/double click should do anything: e.g. expand/collapse the item?G.M.
Also note that Qt generally tries to follow a platform's 'expected' behaviour for this sort of user interaction, so deliberately going against that might not be a good idea.G.M.
Yes, I want the second click to toggle it just like the first. Double click on the item text triggers an edit event. The first click should absolutely toggle it. The second click should also toggle it. This was how Qt 5.0.2 did it, and my workflow means that is definitely the more efficient and preferred action. This wouldn't be a big issue except the double click timer is so damn long, it picks up normal second clicks and blocks them.mrg95

1 Answers

0
votes

I was able to solve this by subclassing QProxyStyle and checking for the style hint SH_ListViewExpand_SelectMouseType and returning a value of 3 instead of the default 2.

class MyProxyStyle : public QProxyStyle
{
public:
    int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const
    {
        if(hint == QStyle::SH_ListViewExpand_SelectMouseType)
            return 3;
        return QProxyStyle::styleHint(hint, option, widget, returnData);
    }
}