View Full Version : QFileSystemModel stylesheet conflict

4th June 2014, 17:53
Hi all,
I have problem of conflict with stylesheet and QFileSystemModel arrows.
Is QFileSystemModel should be avoided to be used ? I read on different forums that it's deprecated like QDirModel.
The problem is when I go in a folder but it has no sub-folder and then if you close the parent and reopen, it's replaced by stylesheet.
I read that a custom QFileSystemModel can be faster than using the one in Qt ?
Is it possible to inherit QFileSystemModel to avoid this arrow and just use the QTreeView stylesheet ?
I already inherit QFileIconProvider to have custom folder icon.
Is it possible to have this folder icon in stylesheet ?
Thanks for the help

5th June 2014, 08:53
What do you mean that a folder is replaced by stylesheet? What do you mean by "QTreeView stylesheet"? QTreeView doesn't have any stylesheets...

5th June 2014, 15:07
I mean it uses :

border-image: url(StyleSheets/Default/branch-vline.png);

border-image: url(StyleSheets/Default/branch-more.png);

border-image: url(StyleSheets/Default/branch-end.png);

But that use this stylesheet only when I close a parent and reopen it with all item opened, before doing this action, it has arrow on the left of each item.
One thing weird too is that replace an item with no children by the good stylesheet image but before doing the action, one arrow is on the left of the item.
Here a screenshot before and after doing this action. I would only use the stylesheet if possible.

Step1 : I open a folder

Step2 : I open each folder, they have no children

Step3 : I close the parent folder and reopen it

5th June 2014, 15:33
What you explain here has nothing to do with QFileSystemModel.

5th June 2014, 15:59
I use differents QTreeView in different widgets I never have problem, only using QFileSystemModel on a QTreeView gives me this problem.
If it's not about QFileSystemModel, I don't understand.

5th June 2014, 16:25
QFileSystemModel is a model while you are having problems with the view. The parts of the view that you are styling are not related to the content of the model.

5th June 2014, 17:26
I need your help to have the correct part because in the doc of Qt there is no informations, that demand to inherit one class to avoid this Qt bug ?
EDIT : Apparently to avoid this problem an item delegate has to be written ? I have tried without stylesheet, it contains the problem too.

6th June 2014, 09:56
Writing a delegate will not help as, again, what you are styling is not related to the model in any way. It is part of the view so the only way to override it is to subclass the view and reimplement drawBranches() and drawRow().

6th June 2014, 18:26
Here the solution :

class CFileSystemModel : public QFileSystemModel

CFileSystemModel( QObject* Parent ) :
QFileSystemModel( Parent )

virtual bool hasChildren( const QModelIndex& parent = QModelIndex() ) const
if( parent.flags() & Qt::ItemNeverHasChildren )
return false;
return QDirIterator( filePath( parent ), filter(), QDirIterator::NoIteratorFlags ).hasNext();

That solves the problem of stylesheet and the problem of arrow when empty.