Important: Please read the Qt Code of Conduct -

Adding data to Frozen Column QTreeWidget

  • I have created a frozen column QTreeWidget (first column is not scrollable), by sharing model with a QTreeView and using viewport->stackUnder.

    1. Any child row is to be added only when parent is expanded. This works fine for the frozen QTreeView, but any data in other columns do not get displayed in the underlying QTreeWidget, so all other columns are blank for child rows. (Verified that the child QTreeWidgetItem does contain the data for other columns)

    2. The data added does not get displayed in-order in the widget i.e. even though I insert with QTreeWidget::addTopLevelItem in a loop, the actual output does not match the order in which the items are added.

    What is the correct way of writing this? Also, I tried using QTreeView and QAbstractItemModel but that further complicates the model and could not get it working. Is writing a dedicated model the only way?

  • Never mind, I solved both of the problems.

    1. Issue was with hooking up event handlers and from where child items were being populated.
    2. Default sorting was enabled, which was leading to this.

  • Lifetime Qt Champion

    So you made something like

    With tree views ?

    Good work :)

  • Yes inspired from that example, though some modification specific to QTreeView, but everything now works except for few hiccups regarding child row visibility. Posted a separate question.

Log in to reply