[Qt-interest] QFileSystemModel some questions

Alex Custov alex.custov at gmail.com
Sat Apr 4 00:06:23 CEST 2009


2009/4/3 Alexis Ménard <alexis.menard at trolltech.com>:
> On Friday 03 April 2009 21:34:32 Alex Custov wrote:
>> 2009/4/3 Alexis Ménard <alexis.menard at trolltech.com>:
>> > On Friday 03 April 2009 19:56:14 Alex Custov wrote:
>> >> Hi.
>> >>
>> >> I'd like to try QFileSystemModel with different views. It seems to
>> >> work, but it misses several important features. Well,
>> >>
>> >> 1) How to show system-wide MIME icons for files? Currently all of them
>> >> are blank. Directory icons seems to work, but all files have blank
>> >> icons.
>> >
>> > If you want to be able to see that then you can create you own
>> > fileiconprovider that do this job. Be carefull of performance.
>> > You can set it to the model using setFileIconProvider. On Windows and
>> > Mac
>> > we query the OS to get the icon. On Linux not so we display the default
>> > blank icon.
>> >
>> >> 2) How to always show directories first (say in QTreeView)?
>> >
>> > It is always like that if you use the default sorting. At least in
>> > 4.5.0,
>> > i am sure.
>>
>> I use 4.4.3 in Debian Lenny, and it mixes directories and files. For
>> example:
>>
>> model = new QFileSystemModel;
>> model->setResolveSymlinks(true);
>>
>> root = model->setRootPath(QDir::rootPath());
>>
>> view->setModel(model);
>> view->setRootIndex(model->index(root));
>>
>> "view" is a QTreeView with "sortingEnabled" set to "true".
>
> So it is perhaps a bug in 4.4.3 i remember a task for that but don't know it
> pushed the patch in 4.4.3. Here in 4.5 how i construct the view for the
> QFileDialog :
>
> void QFileDialogTreeView::init(QFileDialogPrivate *d_pointer)
> {
> d_ptr = d_pointer;
> setSelectionBehavior(QAbstractItemView::SelectRows);
> setRootIsDecorated(false);
> setItemsExpandable(false);
> setSortingEnabled(true);
> header()->setSortIndicator(0, Qt::AscendingOrder);
> header()->setStretchLastSection(false);
> setTextElideMode(Qt::ElideMiddle);
> setEditTriggers(QAbstractItemView::EditKeyPressed);
> setContextMenuPolicy(Qt::CustomContextMenu);
> }
>
> Nothing special. And if i had an seticonsize in this part then it works.
>
>>

fl::fl(QWidget *parent) : QTreeView(parent)
{
    setSortingEnabled(true);

    QFileSystemModel *model = new QFileSystemModel(this);
    model->setResolveSymlinks(true);

    QModelIndex root = model->setRootPath(QDir::rootPath());

    setModel(model);
    setRootIndex(root);
}

and the result is -
http://img159.imageshack.us/img159/7394/view4e.png. Completely broken.

--




More information about the Qt-interest-old mailing list