c++ - Confusion of column count for tree views -


Text after "

In the following example, each child is considered to have 2 columns, although the item is only 1 column.

(MyTreeModel is a subclass of QAbstractItemModel.)

  Integrate MyTreeModel :: columnCount (constant QModelIndex & rParent / * = QModelIndex () * /) static {if (RParent.isValid ()) {Return 2; } And {return1; }}  

In the following example, QTreeView display the column for 2 items for parent items and 1 child items, as expected.

  Integrate MyTreeModel :: columnCount (Const QModelIndex and rparent / * = QModelIndex () * /) const {if (rparent.isValid ()) {return1; } And {return2; }}  

It seems that the column number of the hair objects is limited by the column number of its original item. Is this standard behavior? Am I doing something wrong?

I checked the source code (currently not working) and found the answer as follows:

  1. I checked the method there I used the line D-> title-> Setmodel (model); Found . Header that you want
  2. , this is QHeaderView .
  3. Then check the method
  4. Once the connection is made: QObject :: disconnect (D> model, hint (columnsInserted (QModelIndex, int, int)), this , Slots (sectionsInsterted (QModelIndex, int, int));
  5. The slot method
  6. The last thing I did was read

Looks like I've got it there:

 < Code> Zero QHeaderView :: sectionsInstated (constant QModelIndex & parent, integer logicalFirst, integer logicalLast) {Q_D (QHeaderView); If (parent! = D-> route) returns; // We only handle variations in the top level  

Therefore only top level items have an effect on the number of columns.


Comments