QDirModel lowlevel acces to model items for add it
I use QTreeView + QDirModel, for view my catalog. My catalog have one file 'File1.txt'. But I need display second file ‘File2.txt’ in QTreeView but don’t create this file in my catalog!.
File2.txt have been to QDirModel and display in QTreeView but not create physically on my drive when be located my catalog i.e. I`am not use Filters.
MyCatalog
-- File1.txt - Realy file in my catalog
-- File2.txt - Only display file in QTreeView!
I create class with reimplemented method “insertRow()â€:
Code:
{
public:
DirModelMod();
~DirModelMod();
private:
};
But how I`am can add item (files) in insertRow()?
Please litle sample how add item in QDirModel in reimplement insertRow() or what I need using. And then for setData() I`am understand myself. Tnks.
PS I`am not insert ‘File2.txt’ in QTreeView because it created in QT Designer and file must view in other widgets.
PS Sr for my English ;)
Re: QDirModel lowlevel acces to model items for add it
Try describing your problem again in some simpler words and proper sentences. It is hard to understand what you have, what you need and what doesn't work.
Re: QDirModel lowlevel acces to model items for add it
Quote:
Try describing your problem again in some simpler words and proper sentences. It is hard to understand what you have, what you need and what doesn't work.
I have catalog where only one file:
http://spiribit.com/support/temp/explorer.jpg
My program display it via QTreeView + QDirModel:
http://spiribit.com/support/temp/myprogram.jpg
But I need display second file in QTreeView without creation this file:
http://spiribit.com/support/temp/need.jpg
I think modification method insertRow () and then manually add it:
Code:
insertRow( 1, rootIndex );
setData
( this
->index
( 1,
0, rootIndex
),
QVariant("N:/File2.txt"), FilePathRole
);
setData
( this
->index
( 1,
0, rootIndex
),
QVariant("File2.txt"), FileNameRole
);
But I`am don’t know how modification method:
Code:
bool insertRow ()
{
……
}
Re: QDirModel lowlevel acces to model items for add it
Either subclass the model and reimplement rowCount() and data() to return the additional item or use a proxy model wrapping the base model and add the artificial item there. Touching insertRow (or rather insertRows) from the dir model is not a good idea.
Re: QDirModel lowlevel acces to model items for add it
Depending on how much of QDirModel you are using, you may even find that it's worthwhile creating your own model based on QAbstractItemModel and using QDirIterator, but that is a little like using a sledgehammer to crack a nut :) It depends on what your design shows for future versions of your class.