PDA

View Full Version : Should I use QTreeView or QTableView?



wladek
21st July 2010, 07:43
Hi all,

I have an application which is written in C# and uses the Control called ListView. Please refer to the attacheded picture to see what I am talking about.

Now I need to implement the same behaviour in Qt code, and I am trying to find the best implementation solution.

Here comes my following questions:
1. Should I use the Model/View framework (I haven't used this and I would take me a while to implement it, but maybe it would worth it)?
2. Should I use the QTree* family or the QTable* one? For example, I could use a QTreeWidget and call setRootIsDecorated(false) on it.
3. It seems easier to implement the Model Class on a QTableView than on a QTreeView. Am I right here?

What would be the best way to go?

Thanks in advance for any advice.

Regards,
Wladek

Lykurg
21st July 2010, 07:47
The image looks like a QTable* to me. If it has only some rows, I wouldn't implement a own model, just use QTableWidget.

If you want to show all drives on your computer have a look a QFileSystemModel since Qt provides it and so you don't have to create your own model.

wladek
21st July 2010, 07:54
Hi Lykurg,

Please allow me to explain what I need to do.

My application (GUI) communicates with a service and receives from it some information about the list of devices (USB, floppy, CD-ROM, etc....).
I need to parse this information and to display it in the interface.

I have just read about QStandardItemModel and QStandardItem. Do you think this could be a good approuch?

Or should I just use, as you said, QTableWidget and populate it from my information?

Again, thanks in advance,
Wladek

Lykurg
21st July 2010, 08:08
Well, it depends on you. The high end solution and most elegant one is surely the model approach. But there you have to decide: Use a predefined model like the QStandartItemModel you mentioned or write your own. For that see http://doc.trolltech.com/latest/model-view-creating-models.html.

Now, if you only receive little information from that service and the items doesn't change often, my opinion is that a custom model is not worth to use (and code it). Also because you only have to deal with standard informations and nothing special at all.

So there are only QTableWidget and QStandartItemModel are left. And if I remember right, QTableWidget uses QStandartItemModel internal. So, if you only have one place in your application where you want to show the informations you get from the service, then use a QTableWidget, since it is (for the most people) easier to use. If you have more "places" in your application where you want to show the devices then use QStandartItemModel and pass the model around.

wladek
21st July 2010, 08:28
There is only one place where I need to show this list.

So I decided to use the QTableWidget object and to populate it each time something changes.

Thanks man.

Regards,
Wladek