QStandardItem subclassing?
-
hi,
can any one tell me with a sample code on how to subclass QStandardItem in order to use QStandardItemModel,QtreeView. -
what did you try and what didn’t work?
-
hi all,
never mind i got it. -
Hi, can you please put here a simply code? because i have the same problem as you had
-
I need to override method of QStandardItem operator<(), but thats not the problem, problem is i dont know how to use myItem in models
-
I have subbclassed QStandardItemModel already, so I just try to set in constructor something like this: this->setItemPrototype(new myItem());
-
You normally should not need to subclass QStandardItemModel itself, you should be able to use it without subclassing.
Anyway, your call to setItemPrototype should work. However, did you think to reimplement the QStandardItem::clone() method to return an instance of your own class?
-
Yes, I did it, and i debug if it is called, and it works, but my method operator<() is never called
-
I just tried to create two new myItems and compare them, it works, but thats predictable
but when I called for example myModel->item(r,c)->operator <(other myItem) it isnt called -
@ bool operator <(const myItem &other) const;
virtual myItem *clone() const;@and, after i setItemPrototype, will it take care of retrieving myItem insted of QStandardItem? or i must reimplement or functions which i am working with?
-
Are you sure about that space between operator < ?
And yes, thanks to polymorphism, your own function should be called if it actually is an object of your own type. How do you actually set your items? The prototype is just for editing and things like that. How do you fill your model?
-
no, i delete it
i fill it with functions setItem or setData
-
yes i know, but the code is really big...
@
myModel->setItem( row, column, new myItem(QIcon(icon), "some text") );
myModel->setData( myModel->index(row, column), "text" );
@ -
So, extract the relevant sections yourself, or create a small, self-contained example that shows the problem. Also, when posting code, please use @ tags around your code section (I already updated your post in this case) to improve readability.
Your code, as far as I can oversee it, looks fine to me. I have no idea why it should fail.