Qt6 QML Book/模型视图/概念

本文介绍了QML中模型-视图-委托模式的概念,该模式将数据表示与可视化分离,使同一数据能以不同方式展示。模型负责提供数据,视图处理布局,而委托则根据模型内容进行可视化。这种分工使得用户界面更灵活,适应不同任务需求。
摘要由CSDN通过智能技术生成

Concept

概念

A common pattern when developing user interfaces is to keep the representation of the data separate from the visualization. This makes it possible to show the same data in different ways depending on what task the user is performing. For instance, a phone book could be arranged as a vertical list of text entries, or as a grid of pictures of the contacts. In both cases, the data is identical: the phone book, but the visualization differs. This division is commonly referred to as the model-view pattern. In this pattern, the data is referred to as the model, while the visualization is handled by the view.

开发用户界面时,一种常见模式是将数据的表示与可视化分开。这使得可以根据用户正在执行的任务,以不同的方式显示相同的数据。例如,电话簿可以放在一个垂直的文本条目列表中,或者是一个联系人图片网格。在这两种情况下,数据是相同的,都是电话簿,但可视化显示不同。这种划分通常称为模型视图模式。在此模式中,数据称为模型,而可视化由视图完成。

In QML, the model and view are joined by the delegate. The responsibilities are divided as follows: The model provides the data. For each data item, there might be multiple values. In the example above, each phone book entry has a name, a picture, and a number. The data is arranged in a view, in which each item is visualized using a delegate. The task of the view is to arrange the delegates, while each delegate shows the values of each model item to the user.

在QML中,模型model和视图view由委托delegate连接。职责划分如下:模型为每个数据项提供数据,可能有多个值。在上面的示例中,每个电话簿条目都有一个姓名、一张图片和一个电话号码。数据被安排在一个视图中,在该视图中,每个项目都使用委托进行可视化。视图的任务是安排委托,而每个委托向用户显示每个模型项的值。

This means that the delegate knows about the contents of the model and how to visualize it. The view knows about the concept of delegates and how to lay them out. The model only knows about the data it is representing.

这意味着委托知道模型的数据以及如何可视化模型数据。视图了解委托的概念以及如何安排它们。模型只知道它拥有的数据。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值