3

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.

QCalendarWidget

fs_tigre
  • 10,650
  • 13
  • 73
  • 146

1 Answers1

3

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

Community
  • 1
  • 1
Prad Lal
  • 113
  • 7
  • Thank you for your reply. Sorry I meant to say QStringListModel and a QTableView, but yes in general I'm still learning MVC. Thanks a lot for your suggestions, I will look into it and give it a try. – fs_tigre Jul 31 '13 at 11:28
  • 1
    I was learning all this not very long ago, and always having doubts of which class to use for a particular data, so I understand. You get the hang of it after a while. By the way, QStandardItemModel is more suited than the QStringListModel since you have more than just the string to store per entry. – Prad Lal Jul 31 '13 at 12:18