Creating a QAbstractItemModel for QTreeView
hi
- I want know how subclassin a QAbstractItemModel to create a model for QTreeView
- how can i create my model like QDirModel using QAbstractItemModel ? i want display more informations of files and directories in a QTreeView (owner .....)
thank you
Re: Creating a QAbstractItemModel for QTreeView
Quote:
Originally Posted by
hbill
- I want know how subclassin a QAbstractItemModel to create a model for QTreeView
There are many resources available on that topic. Take a look at the [wiki=QAbstractItemModel]wiki[/wiki].
Quote:
- how can i create my model like QDirModel using QAbstractItemModel ? i want display more informations of files and directories in a QTreeView (owner .....)
Subclass QDirModel and reimplement appropriate methods calling base class implementations where needed.
Re: Creating a QAbstractItemModel for QTreeView
Quote:
Originally Posted by
hbill
hi
- I want know how subclassin a QAbstractItemModel to create a model for QTreeView
model like QDirModel
thank you
you can build tree from QStandardItemModel begin to read xml tree or sql tree demo
http://www.klempert.de/nested_sets/demo/
run on mysql or on sqlite3
each level become a QList<QStandardItem *>
model = new QStandardItemModel();
model->invisibleRootItem()->appendRow(QList<QStandardItem *>);
sublevel the first QStandardItem appendRow(QList<QStandardItem *>)
code on http://www.qtforum.de/forum/viewtopic.php?t=5845
To swap from one model to other you can use:
http://fop-miniscribus.googlecode.co....0/ModelSwap.h
http://fop-miniscribus.googlecode.co.../ModelSwap.cpp
I use this to print on tree or tableview to QTextDocument
Re: Creating a QAbstractItemModel for QTreeView
thank you
can you help me to subclassing QDirModel, :(
Re: Creating a QAbstractItemModel for QTreeView
Quote:
Originally Posted by
hbill
can you help me to subclassing QDirModel, :(
What's causing problems? What did you try so far? Let's say you wanted to add one column:
Code:
{
public:
...
// reimplement columnCount()
virtual int columnCount
(const QModelIndex
& parent
= QModelIndex()) const;
...
};
int MyDirModel::columnCount(const QModelIndex& parent) const
{
// call base class implementation and add 1 to whatever it returns
}
This is just an example to get you going. Most likely you don't want to return 1 as column count when the base class returns 0. Next thing to do is to reimplement data() and make it handle this additional column.
Re: Creating a QAbstractItemModel for QTreeView
hi
Code:
MyDirModel
:: MyDirModel(QObject *parent
){
}
MyDirModel::~MyDirModel()
{
}
int MyDirModel::columnCount(const QModelIndex& parent) const
{
}
{
if( role==Qt::DisplayRole )
{
if( index.
column()==QDirModel::columnCount() ) return fileInfo( index ).owner();
else
if( index.
column()==QDirModel::columnCount() +1 ) return fileInfo( index ).group();
}
}
the column "last modified" was not removed and the new columns are empty :o
Re: Creating a QAbstractItemModel for QTreeView
QDirModel does not implement QAbstractItemModel::removeColums() so you can't use it. Either hide it from the view or make the subclass return alternative data for that particular column. Start with checking out if anything shows up in those columns when you return a fixed test string. After that, continue with investigating whether the QFileInfo returned by fileInfo() is ok.
Re: Creating a QAbstractItemModel for QTreeView
hi
Code:
{
//msgBox.exec();//ok
if( role==Qt::DisplayRole )
{
//msgBox.exec();//ok
if( index.
column()==QDirModel::columnCount() )//problem {
//msgBox.exec();//not ok
return fileInfo( index ).owner();
}
else
if( index.
column()==QDirModel::columnCount() +1 )//problem return fileInfo( index ).group();
else
if( index.
column()==QDirModel::columnCount() -1 ) {
//msgBox.exec();//ok
return fileInfo( index ).owner();//ok
}
}
}
i have a problem with the new columns !!! :confused:
Re: Creating a QAbstractItemModel for QTreeView
Quote:
Originally Posted by
hbill
i have a problem with the new columns !!! :confused:
Could you be a bit more verbose about the problem, please?
Re: Creating a QAbstractItemModel for QTreeView
Quote:
Originally Posted by
jpn
Could you be a bit more verbose about the problem, please?
Yeah... a more verbose version is "they are not working!" :D
Sorry, couldn't resist myself...
Re: Creating a QAbstractItemModel for QTreeView
the test
Code:
if( index.column()==id_column )
is virified if id_column <QDirModel::columnCount()
but no if id_column >=QDirModel::columnCount()
Re: Creating a QAbstractItemModel for QTreeView
Could you check if your columnCount() method is called at all?
Re: Creating a QAbstractItemModel for QTreeView
Did you ever find a solution to the column data not being added?
Re: Creating a QAbstractItemModel for QTreeView
Your problem may have been similar to mine. What version of Qt are you using. I upgraded from 4.3.2 to 4.4.1 on solaris, and my problems went away.