Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top