如何在Qt中显示选定的日期和数字 [英] How to display a selected date and a number in Qt

查看:1318
本文介绍了如何在Qt中显示选定的日期和数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用QCalendar小部件,我需要一些想法来完成以下操作。

I'm currently working with the QCalendarWidget and I need some ideas to accomplish the following.

从QCalendarWidget添加selecteDate的最佳方法是什么?一个数字到某种表。我想要的基本上是有一个附加到每个日期的数字的日期列表,这些数字将被添加在一起,结果将显示在一个QLabel,我也希望能够删除行,并再次更新QLabel每

What would be the best way to add the selecteDate from a QCalendarWidget and a number to some sort of table. What I want is basically to have a list of dates with a number attached to each date, these numbers will be added together and the result will be displayed in a QLabel, I also want to be able to delete rows and again update the QLabel every time a row is deleted.

我也希望能将列表保存到外部文件。

I also want to be able to save the list to an external file.

我应该使用QStringListModel还是QTableView?

Should I use a QStringListModel or a QTableView?

如何实现?

请参阅附图了解更多详情。

Please see the attached image for more details.

推荐答案

em>我应该使用QStringListModel还是QTableView?

Should I use a QStringListModel or a QTableView?

您可能想要熟悉模型/视图框架。简单来说,模型是你拥有的实际数据,它独立于如何显示它。视图是模型的特定显示实现。所以你可以使用像QStandarItemModel这样的模型来存储你的String +数字数据并在QTableView中显示模型。

You may want to familiarize yourself with the model/view framework. To put it simply, a model is the actual data that you have and it is independent of how it should be displayed. A view is a particular display implementation of a model. So you could use a model like the QStandarItemModel to store your String+number data and display the model in a QTableView.

来自Qt网站的模型/视图教程 here
QStandardItemModel类此处。里面有一个简单的例子。

Model/View Tutorial from Qt website here QStandardItemModel class here. Has a simple example inside there.

并且,为了写入和读取数据到文件,我建议你可以使用QXmlStreamWriter / Reader类。请参阅 QT xmlwriter / xmlreader

And, for writing and reading the data to a file, I suggest you could use the QXmlStreamWriter/Reader classes. Refer to QT xmlwriter/xmlreader

这篇关于如何在Qt中显示选定的日期和数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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