0

I want to implement a tree view like the visual studio solution explorer with Qt. The tree is used to represent an external data called "project". I want to use Qt model/view architecture.

(1) QTreeView for the view, and the model is derived from QAbstractItemModel which include a pointer pointing to the project object. (2) The items under a directory are sorted by its name. When adding an item under a directory, it will automatically be put on the right position. (3) When double clicking an item in the tree, a dialog will pop up for editing.

Any good ways to implement the (2) and (3). Thanks a lot!

user1899020
  • 13,167
  • 21
  • 79
  • 154

1 Answers1

1

Ad 2) Taking a look here might be helpful: http://doc.qt.digia.com/qt/qsortfilterproxymodel.html. It contains examples of implementing a more complex sorting and filtering of the items.

Ad 3) Overrride QTreeView::mouseDoubleClickEvent().

Just a side note, as an alternative, you could use QTreeWidget and QTreeWidgetItem, in which case you might want to traverse the tree and insert child items directly at the position you want.

ellimilial
  • 1,246
  • 11
  • 20
  • Thank you for your suggestion. I am wondering the benefits of using QTreeWidget. I also need to use data widget mapper. Is it possible to user it with QTreeWidget? For a directory item, when double clicked, I hope to see a table view of all the items under the directory. May I need to make a model for the table view from the original model? Any good suggestion to implement it? Thanks a lot again! – user1899020 Dec 17 '12 at 22:14
  • 1
    QTreeWidget would give you some additional flexibility with items if you do not want to care about underlying data. In general you might prefer to stick to model/view most of the time. If you will do a lot of rearranging, changing parents and cannot find a good underlying structure, it might be easier to use QTreeWidget directly. In this case definitely take a look [here](http://qt-project.org/doc/qt-4.8/itemviews-simpletreemodel.html) for the basic implementation guidelines. As to the reusability - you could use the same model and initialise it with different roots - eg. full path for QDir. – ellimilial Dec 17 '12 at 22:37