Created
May 17, 2023 14:02
-
-
Save SC-One/10f515261d20fdf41db0237ea51ece6f to your computer and use it in GitHub Desktop.
How subclassing QAbstractTableModel in qt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FooTableModel : public QAbstractTableModel { | |
Q_OBJECT | |
public: | |
FooTableModel(QObject *parent = nullptr); | |
// readonly tables | |
Qt::ItemFlags flags(const QModelIndex &index) | |
const override; // editable can return: Qt::ItemIsEditable | |
QVariant data(const QModelIndex &index, | |
int role = Qt::DisplayRole) const override; | |
QVariant headerData(int section, Qt::Orientation orientation, | |
int role = Qt::DisplayRole) const override; | |
int rowCount(const QModelIndex &parent = QModelIndex()) const override; | |
int columnCount(const QModelIndex &parent = QModelIndex()) const override; | |
QHash<int, QByteArray> roleNames() const override; | |
// editable model have methods(we dont need them now , and even later): | |
bool setData(const QModelIndex &index, const QVariant &value, | |
int role = Qt::EditRole) override; | |
bool setHeaderData(int section, Qt::Orientation orientation, | |
const QVariant &value, int role = Qt::EditRole) override; | |
// resizeAble model have methods: | |
bool insertRows(int row, int count, | |
const QModelIndex &parent = QModelIndex()) override; | |
bool removeRows(int row, int count, | |
const QModelIndex &parent = QModelIndex()) override; | |
bool insertColumns(int column, int count, | |
const QModelIndex &parent = QModelIndex()) override; | |
bool removeColumns(int column, int count, | |
const QModelIndex &parent = QModelIndex()) override; | |
private: | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment