PDA

View Full Version : QAbstractItemView problem



Kostanev
12th September 2007, 01:13
How I can property inherit that class? I done something like that:



class OptionalModel : public QAbstractItemView
{
Q_OBJECT

public:
OptionalModel(QWidget *parent = 0);
~OptionalModel();

QRect visualRect(const QModelIndex &index);
void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible);
QModelIndex indexAt(const QPoint &point);
QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
int horizontalOffset();
int verticalOffset();
bool isIndexHidden(const QModelIndex &index);
void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command);
QRegion visualRegionForSelection(const QItemSelection &selection);

private slots:
void selectAll();
};


Of cource its initalised in one .cpp file but I still get this error when compiling:
error C2259: 'OptionalModel' : cannot instantiate abstract class

What I must do to fix that ?

marcel
12th September 2007, 06:31
You didn't reimplement all abstract methods or you didn't declare them correctly.
For instance, indexAt should be const:


QModelIndex indexAt ( const QPoint & point ) const;


Also, visualRect is also const.
So take another look at the QAbstractItemView interface and define all functions properly.

Regards

Kostanev
12th September 2007, 21:26
Thank you...

Kostanev
13th September 2007, 20:05
Ok I will ask one more question here, I now use QStandardItemModel as constructor and I found how to add items but they all seems like children, no parent... How I can create parent for some child items?

wysota
13th September 2007, 22:32
You can't add parents. If you add a child item to an item, you at the same time determine that the first item is the parent of the other. You can't have more than one parent for an item and you can't build the tree bottom-up, only top-down. I hope I understood your question :)