0

I'm implementing a Model/View for a tree like structure, and I've decided to try the QStandardItemModel on which I want to wrap on it a specific class, (which I call here "appSpecificClass").

Basically, I want part of that class (like names, or some data), to be shown in the model, and when I change the model (in edit role, or drag and drop), I want that to have consequences on the appSpecificClass (which is, when I change a name that is showing on the model, the name on the object associated with the model's item of the appSpecificClass also changes).

So, I started from subclassing the QStandardItem by a appSpecificItem, which only has a pointer to the appSpecificClass. When I construct the appSpecificItem, the text and icons are called from appSpecificClass and everything works fine.

However, when change data from appSpecificItem, naturally it does not change the appSpecificClass, because so far I didn't found any way of interacting with the appSpecificItem's pointer via overloading a virtual function (or else)

Does anyone knows how to do this/if this is possible? What can I do such that if for instance the signal

QStandardItemModel::itemChanged ( QStandardItem * item )

is emitted, I can change a the appSpecificItem's pointer.

If not, is there any good tutorial about implementing a Model from scratch? I've tried myself some, but it is not an easy task. Ideally I would like a QStandardItemModel like model, but a little more abstraction on it (such that I can put my appSpecificClass on it).

leemes
  • 44,967
  • 21
  • 135
  • 183
Jorge Leitao
  • 19,085
  • 19
  • 85
  • 121
  • 1
    Check how is QStandardItemModel impemented. It uses QAbstractItemModel so it may give you some hints how to create own model – Kamil Klimek May 28 '12 at 16:28
  • I agree with @KamilKlimek, although creating your own model involves a good amount of coding, it is fairly straight forward. It'll probably be easier and less error-prone than what you are trying to do now. There's a sizeable tutorial on the Qt site (http://doc-snapshot.qt-project.org/4.8/modelview.html) for model/view programming. – cmannett85 May 29 '12 at 06:45
  • Creating a rudimentary model requires reimplementing just a few methods listed in the docs: http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#subclassing – Kuba hasn't forgotten Monica May 31 '12 at 21:57

0 Answers0