How to display a selected date and a number in Qt

寵の児 提交于 2019-12-10 17:49:34

问题


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

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.

Should I use a QStringListModel or a QTableView?

How would you accomplish this?

I'm not expecting any code just a general procedure.

Please see the attached image for more details.


回答1:


Should I use a QStringListModel or a 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.

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

And, for writing and reading the data to a file, I suggest you could use the QXmlStreamWriter/Reader classes. Refer to Qt xmlWriter/xmlReader



来源:https://stackoverflow.com/questions/17960194/how-to-display-a-selected-date-and-a-number-in-qt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!