QTreeView & QAbstractItemModel & insertRow

前端 未结 1 1932
故里飘歌
故里飘歌 2021-01-12 17:14

I\'m trying to implement QAbstractItemModel for QTreeView. I have problem with inserting rows. I noticed that if I insert at the beginning of my application all works fine.

相关标签:
1条回答
  • 2021-01-12 17:19

    Just a quick guess, the QT Doc for QAbstractItemModel says...

    The model emits signals to indicate changes. For example, dataChanged() is emitted whenever items of data made available by the model are changed. Changes to the headers supplied by the model cause headerDataChanged() to be emitted. If the structure of the underlying data changes, the model can emit *layoutChanged() to indicate to any attached views that they should redisplay any items shown, taking the new structure into account*.

    So i guess, you need to emit layoutChanged() signal from your model (whenever you change the data in model) in order to update connected views.

    Also read the QT docs for model view architecture, how it is implemented in QT

    see if that helps, if it doesn't i will try to download your code and debug it and see, what's wrong. Good Luck

    0 讨论(0)
提交回复
热议问题