QTableView
Verfasst: 7. Oktober 2008 18:54
Also ich habe eine Tabelle QTableView mit dem QDesigner erstellt nun will ich die Tabelle füllen. Dazu habe ich gelesen gibt es in QT das Model-View Konzept. Mein View (QTableView) habe ich ja schon, also brauche ich noch mein Model (MyTableViewModel
) Dazu habe ich gefunden ich sollte die QAbstractTableModel ableiten. Also habe ich eine MyTableViewModel Klasse erstellt die von QAbstractTableModel erbt. Dann habe ich wichtige Funktionen wie removeRow() usw. eingebunden. Das funktioniert ja auch schön und gut aber wie greife ich auf die einzelnen Spalten zu?
Mein Quellcode falls er wem hilft mir zu helfen
MyTableViewModel.h
MyTableViewModel.cpp (ist noch nicht fertig)
Mein Quellcode falls er wem hilft mir zu helfen
MyTableViewModel.h
Code: Alles auswählen
#ifndef __MYTABLEVIEWMODEL_H__
#define __MYTABLEVIEWMODEL_H__
#include <QStringList>
#include <QAbstractTableModel>
class MyTableViewModel : QAbstractTableModel
{
public:
MyTableViewModel(QObject *parent = 0);
~MyTableViewModel();
int rowCount( const QModelIndex & parent = QModelIndex() );
int columnCount( const QModelIndex & parent = QModelIndex() );
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole);
QVariant headerdata( int section, Qt::Orientation orientation, int role = Qt::DisplayRole);
bool setData( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
Qt::ItemFlags flags( const QModelIndex & index );
bool insertRows( int row, int count, const QModelIndex & parent = QModelIndex());
bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex() );
bool insertColumns( int column, int count, const QModelIndex & parent = QModelIndex() );
bool removeColumns( int column, int count, const QModelIndex & parent = QModelIndex() );
}
#endif // __MYTABLEVIEWMODEL_H__
Code: Alles auswählen
#include "MyTableViewModel.h"
MyTableViewModel::MyTableViewModel(QObject *parent) : QAbstractTableModel(parent)
{
}
int MyTableViewModel::rowCount( const QModelIndex & parent)
{
}
int MyTableViewModel::columnCount( const QModelIndex & parent)
{
}
QVariant MyTableViewModel::data(const QModelIndex & index, int role)
{
}
QVariant MyTableViewModel::headerdata( int section, Qt::Orientation orientation, int role)
{
}
bool MyTableViewModel::setData( const QModelIndex & index, const QVariant & value, int role)
{
}
Qt::ItemFlags MyTableViewModel::flags( const QModelIndex & index )
{
}
bool MyTableViewModel::insertRows( int row, int count, const QModelIndex & parent)
{
beginInsertRows(QModelIndex(), row, count);
endInsertRows();
}
bool MyTableViewModel::removeRows(int row, int count, const QModelIndex & parent)
{
beginRemoveRows(QModelIndex(), row, count);
endRemoveRows();
}
bool MyTableViewModel::insertColumns( int column, int count, const QModelIndex & parent)
{
beginInsertColumns(QModelIndex(), column, count);
endInsertColumns();
}
bool MyTableViewModel::removeColumns( int column, int count, const QModelIndex & parent)
{
beginRemoveColumns(QModelIndex(), column, count);
endRemoveColumns();
}