Hello,
I have a QAbstractListModel subclass which has a QList with objects of type "struct Foo". For a custom paint job, I use QStyledItemDelegates for the view. Inside its paint() method, I'd like to handle the real object behind the item directly. So I tried getting it by casting the internal pointer of the model index. This will compile, but only yield 0.
Foo *f = static_cast<Foo*>(index.internalPointer());
Foo *f = static_cast<Foo*>(index.internalPointer());
To copy to clipboard, switch view to plain text mode
The problem here is, that the internal pointer is already 0. In the past I successfully used static casts on internal pointers.
On the other hand, using the model from the index and a custom method in the model works quite well. Yet, this solution looks rather long-winded.
Foo *f = ((FooModel*)index.model()).fooByIndex(index);
// Model definiton (excerpt)
{
public:
}
Foo *f = ((FooModel*)index.model()).fooByIndex(index);
// Model definiton (excerpt)
class FooModel : public QAbstractListModel
{
public:
Foo *fooByIndex(const QModelIndex &index);
}
To copy to clipboard, switch view to plain text mode
Am I missing something here or is the internal pointer supposed to be null?
Andreas
Bookmarks