QTreeView setFirstColumnSpanned() breaks expand/collapse
In my QTreeView and QTreeModel, only the "leaves" of the tree use all the columns; items with children use only the first column. So, for those items, I call QTreeView::setFirstColumnSpanned(). Graphically, that does what I want. The problem is that mouse clicks on the arrows to the left of those items no longer expand/collapse the items. The mouse clicks are ignored. I can use the keyboard to expand/collapse (left arrow, right arrow, asterisk), but not the mouse.
Anybody have any idea why this is happening, and how I might fix it?
Another clue: if I call expandToDepth() in the constructor of my QTreeView subclass, mouse clicks work correctly on the items which are initially expanded, but not on lower levels of the tree.
I am using Qt 5, and have the same problem on both Windows and Linux.
I have made some progress in figuring out what is happening. It depends on the width of the first column.
Say a row spans all the columns, because setFirstColumnSpanned() has been called. If the row is a few levels down in the tree, it is offset to the right, so the arrow icon may be 50 or 100 pixels from the left margin. And if it is deep enough, or the first column is narrow enough, the arrow icon is offset beyond the right edge of the first column. When that happens, Qt will not allow the user to click on the arrow icon.
That is, QTreeViewPrivate::itemDecorationAt() returns -1 in that case, because QHeaderView::logicalIndexAt() returns a non-zero column.
Shouldn't QTreeViewPrivate::itemDecorationAt() take into account the spanning of an item?
I have reported a bug for this: "QTBUG-31384":https://bugreports.qt-project.org/browse/QTBUG-31384