Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt - what's preferred to use - widgets or views? (Tree, Table, List) [closed]

I started to use Qt model-view system with QStandardItemModel and some views. But then I noticed that there are also Widgets - Tree, Table, List, that happend to be almost the same in use as views. I read Qt docs about it and honesty didn't understand for what we need also widgets, why views is not sufficient..

like image 888
ManInTheHood Avatar asked Jan 25 '13 17:01

ManInTheHood


2 Answers

Q*Widgets are easy to use for easy use cases. They might become tedious though to handle when you have to look up and update the items afterwards. Then it's often easier to write a custom model once you groked the concept. Also with lots of items, custom models will have better performance.

Custom models combined with views are more flexible: They allow the use of proxy models, especially QSortFilterProxyModel, which makes basic sorting and filtering quite simple.

If custom models see too daunting (they can become complex especially for tree models) and you still want the flexibility of views and proxies, I suggest to look into QStandardItemModel: It gives you a item-based API like Q*Widget do, but can be combined freely with different proxies and views. Should you at some point decide to go for a custom model, just replace the model and you don't have touch proxies and views at all.

like image 55
Frank Osterfeld Avatar answered Oct 06 '22 01:10

Frank Osterfeld


You should know two things.

How important is speed data load. See this question - Qt model/view vs standard widget.

Do need implementation of QAbstractItemModel that can be more useful than QStandardItemModel? For example, if you already have QVector that need present in a view, for you will be great use own model than standard.

like image 24
synacker Avatar answered Oct 06 '22 01:10

synacker