PDA

View Full Version : QListView v.s. QTreeView, QTableview, QDirModel [solved]



DrDonut
5th March 2009, 10:41
Hi all,

A program I am writing is supposed to display a list of files that are in use, using three columns (Name, Type and Options).

To do this I found the QListView class perfect, because I can simply add columns and items. But now it seems that this is no longer fact in QT 4.

Using Qt3Support, I managed to get this to work, but I want the code to be maintainable in the future, so I need something else.

In the QT examples, they use a number of different things like QTreeview, QTableView, QDirModel and stuff like that, but they all use them at the same time so I don't know what does what.

So can you tell me what I should use to do the same as the old QListView from QT3?

Thanks in advance
DrDonut

ulmly
5th March 2009, 10:54
Try to use QListWidget, or QTreeWidget.

faldzip
5th March 2009, 12:01
QListView has only 1 column but you can use QTreeView (where you can have many columns) with only top level items. It would look like "details" view in Windows Explorer.

faldzip
5th March 2009, 12:26
Or you can use QTreeWidget where you don't need a model, just adding items to QTreeWidget. See the attachment (it's QTreeWidget with 3 columns)

DrDonut
5th March 2009, 12:40
Okay thank you both.

Now I used QTreeView and QStandardItemModel and it works!

I will look into QTreeWidget for the sake of simplicity, but for now it works:D

So thanks!

DrDonut

faldzip
5th March 2009, 12:52
In my opinion, it's better to use view + model than widget, because you have all the benefits from Model/View architecture, mainly data and it's presentation are clearly divided - so your solution is now ok. But sometimes, when you have to show some simple data temporary in only one place and in one way or something like that :D then the problem is not worth of doing model for it and much faster way is to use widget like QTreeWidget.