PDA

View Full Version : Treeview/treewidget to hold list of websites



doniking
8th May 2012, 09:48
Hi,

Can someone please give me a starting point on how to create a treeview which is kinda like IIS Manager

7703

So the main items are the list of websites, and every item has directory structures (from file system) under every website's root documents .

I am totally lost at the model/view/delegate concept.

I will be watching this thread for any reply since i have nowhere to ask this question.

Thanks.

Agnostic Pope
8th May 2012, 21:45
There's two ways of doing this in Qt. One is using an "item-based" approach where each folder/subfolder is its own object and you're responsible for creating them.

Check out QTreeViewWidget ( http://qt-project.org/doc/qt-4.8/qtreeview.html ) to see how you could do it this way.

The second way is a bit more odd. The basic idea is you implement functions saying "hey, how many items do it have" (row count) and "What are they called?" (data) given the parent node (i.e. folder) in the tree. Once you have that information, it will only be requested when when it's needed (i.e. when you open up a folder, it'll look up what stuff's underneath it and create the items automagically). This is more the MVC approach and you'd QAbstractItemModel and re-implement all the virtual functions that have no default implementation in order for this to work. The good news is that once you have the model, all you need to do is create a QTreeView and hand it the model and you're done. In practice, I generally find this approach better and simpler, but less accessible to newer Qt users. ( http://qt-project.org/doc/qt-4.8/QAbstractItemModel.html )

Hope this helps;) Oh and don't worry about delegates. Really, the only thing you need to understand for your example is how your model works. You shouldn't need anything else custom to do this.

doniking
9th May 2012, 14:14
@Agnostic Pope :
How do I save the values (root dir, listen ip, port, etc) on each website items ?
Do i still need to use QDirModel for the dir structures below each website items?

Thank you!

doniking
15th May 2012, 04:27
i think i will get the root dir , ip, port in real time from the config files.

Another question, how do I add the QFileSystemModel as the child of each items?