Re: QDirModel and QTreeView
You mean you want the whole directory path to be displayed for the root item?
Re: QDirModel and QTreeView
yes,
but i can not find examples/solution for this :(
i have all tested ..... or? :confused:
Re: QDirModel and QTreeView
Subclass the model and reimplement data() to return an absolute path for items with invalid parents, more or less like so:
Code:
if((role==DisplayRole || role==EditRole)
&& index.isValid() && !index.parent().isValid())
return filePath(index);
}
Re: QDirModel and QTreeView
the target is nearby :D
Code:
MTWorkSpaceModel *model = new MTWorkSpaceModel();
modelDir
->setFilter
( QDir::AllDirs );
modelDir->setLazyChildCount( true );
QVariant data
= model
->data
( modelDir
->index
( workspace
), Qt
::DisplayRole );
qDebug() << data; // data returns QVariant(QString, "/home/alex/test")
modelDir->setData( modelDir->index( workspace ), data, Qt::DisplayRole );
dirModel = modelDir;
tvWorkspace->setModel( modelDir );
tvWorkspace->setRootIndex( modelDir->index( workspace ) );
tvWorkspace->header()->setSortIndicatorShown( true );
tvWorkspace->header()->setClickable( true );
tvWorkspace->setColumnHidden( 1, true );
tvWorkspace->setColumnHidden( 2, true );
tvWorkspace->setColumnHidden( 3, true );
connect( tvWorkspace,
SIGNAL( clicked
( const QModelIndex & ) ),
this,
SLOT( workspaceItemChanged
( const QModelIndex & ) ) );
MTWorkSpaceModel
Code:
if((role == Qt::DisplayRole || role == Qt::EditRole ) && index.isValid() && index.parent().isValid())
return filePath( index );
}
but not realy function .... why? is the error on
Code:
modelDir->setData( modelDir->index( workspace ), data, Qt::DisplayRole );
or
Code:
tvWorkspace->setRootIndex( modelDir->index( workspace ) );
sorry for my bad english
Re: QDirModel and QTreeView
What exactly doesn't work? Could you describe the problem?
1 Attachment(s)
Re: QDirModel and QTreeView
i have the subclass created and QDirModel reimplemented with QVariant data(...)
in the code (see above) set i the data of QDirModel with my subclass ....
but it is not function, i see in the treeview only the folder
|-ui
|-src
|-include
but not
/home/alex/test
|-ui
|-src
|-include
in short form: i can not see rootItem .....
1 Attachment(s)
Re: QDirModel and QTreeView
See the attached file for a working version.
Re: QDirModel and QTreeView
thank you very much, for this example, i'm so happy and it works *kiss* :D