Hi,
I'm trying to figure out how best to make my own model class but I'm going round in circles figuring out what to inherit from and what to reimplement.
Currently I have it inheriting from QStandardItemModel like so:
{
Q_OBJECT
public:
};
class PlayersModel : public QStandardItemModel
{
Q_OBJECT
public:
PlayersModel(QObject* parent = 0);
};
To copy to clipboard, switch view to plain text mode
And then the constructor is set up like so:
{
this
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("Name"));
this
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("Email"));
}
PlayersModel::PlayersModel(QObject* parent) : QStandardItemModel(0, 2, parent)
{
this->setHeaderData(0, Qt::Horizontal, QObject::tr("Name"));
this->setHeaderData(1, Qt::Horizontal, QObject::tr("Email"));
}
To copy to clipboard, switch view to plain text mode
But then I am aware that the user of PlayersModel could use the add column functions which I don't want them to be able to do. I simple want to define a list of name and email address (and maybe other things later).
Can anyone point me in the right direction of a tutorial (or just simply help by giving me a bit of code to help) which I can use to learn this? I've tried the model view tutorial in the Qt docs but it doesn't really explain what I need.
I would also like to be able to perform drag and drop between table view classes using the same model, which I have no idea how to implement at the moment but am keeping that in mind for now incase it has a bearing on how to implement my model class.
Thanks so much guys!
Bookmarks