QTreeView或QTreeWidget [英] QTreeView or QTreeWidget

查看:1249
本文介绍了QTreeView或QTreeWidget的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的程序中实现一个嵌套子级别的树,我正在寻找两种(View / Widget)中最适合我的目标。



我有一个任务清单,已经完成/错过/失败,每个任务都有多少次完成/错过/失败,最后是当天的分数。



我想像这样显示:





我使用QTreeWidget在QtCreator中做了这个例子,但我担心这将很难修改因为它们被存储在其他地方,所以元素。



我的忧虑是否合理,我应该去模型/视图结构,还是可以很容易地使用QTreeWidget?树将记录任务,因此将不断变化。元素只会被添加到它,而不是删除。天数将从最高最低(第2天是第一天,然后是第1天)排序。

解决方案

如果您的数据存储在数据库模型中,或者如果您想要有一个单一的数据模型,并以不同的方式在某些视图中显示,那么您最好还是使用 QTreeView



但是, QTreeWidget 以某种方式拥有内部模型以及在索引上下文中处理模型的方法。一般来说,如果你只是想要一些简单的工作,你可以使用小部件的方式。



但是,模型/视图方法是更通用和灵活的IMO。您可以创建自己的模型和视图子类,使您能够执行任何您喜欢的任务。


I want to implement in my program a tree with nested sub-levels, and I'm looking for which of those two kind(View/Widget) is best suited for my goal.

I have a list of days with task that are either done/missed/failed, each task has a count of how many times it was done/missed/failed and lastly a score for that day.

I want to display them like so:

I made this example in QtCreator using a QTreeWidget, but I'm worried that it would be hard to modify the elements since they are stored somewhere else.

Are my worries rational and should I go to the model/view structure, or can I easily get going with the QTreeWidget? The tree will be logging the task and thus will be constantly changing. Elements will only be added to it, not removed. And the days will be sorted from highest-lowest(day 2 is first, then day 1)

解决方案

If your data is stored in a database model or if you want to have a single data model and show it in some views in different ways, then you are definitely better to go with QTreeView.

But QTreeWidget has it's internal model in some way along with the methods to deal with model in context of indexes. In general if you just want something that is simple to work, you can use the widget way.

But the Model/View approach is more general and flexible IMO. You can create your own subclasses of model and view which enables you to do whatever you like.

这篇关于QTreeView或QTreeWidget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆