PDA

View Full Version : QFileSystemModel stylesheet conflict



Alundra
4th June 2014, 16: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

wysota
5th June 2014, 07: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...

Alundra
5th June 2014, 14:07
I mean it uses :


QTreeView::branch:has-siblings:!adjoins-item
{
border-image: url(StyleSheets/Default/branch-vline.png);
}

QTreeView::branch:has-siblings:adjoins-item
{
border-image: url(StyleSheets/Default/branch-more.png);
}

QTreeView::branch:!has-children:!has-siblings:adjoins-item
{
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
http://uppix.com/f-Step153906b180016a77f.png

Step2 : I open each folder, they have no children
http://uppix.com/f-Step253906b690016a781.png

Step3 : I close the parent folder and reopen it
http://uppix.com/f-Step353906b890016a782.png

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

Alundra
5th June 2014, 14: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.

wysota
5th June 2014, 15: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.

Alundra
5th June 2014, 16: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.

wysota
6th June 2014, 08: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().

Alundra
6th June 2014, 17:26
Here the solution :


class CFileSystemModel : public QFileSystemModel
{
public:

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.