[Qt-interest] icons for files
Puneet Bisht
pbisht at nivio.com
Sat May 9 09:00:42 CEST 2009
thanks Tanguy Krotoff,
the code really works .
> Then you can create a temporary file on the local harddrive with the
> same extension as the remote file.
> This way QFileIconProvider will give you the right icon.
>
> here some code
>
>
> QIcon fileExtensionIcon(const QString & extension) const {
> static QFileIconProvider iconProvider;
>
> QIcon icon;
>
> QTemporaryFile tmpFile(QDir::tempPath() + QDir::separator() +
> QCoreApplication::applicationName() + "_XXXXXX." + extension);
> tmpFile.setAutoRemove(false);
>
> if (tmpFile.open()) {
> QString fileName = tmpFile.fileName();
> tmpFile.write(QByteArray());
> tmpFile.close();
>
> icon = iconProvider.icon(QFileInfo(fileName));
>
> tmpFile.remove();
> } else {
> qCritical() << __FUNCTION__ << "Error: couldn't write temporary
> file:" << tmpFile.fileName();
> }
>
> return icon;
> }
>
>
> On Tue, May 5, 2009 at 2:27 PM, Puneet Bisht <pbisht at nivio.com> wrote:
>> thanks for your reply
>>
>> i have already tried QFileIconProvider , but the problem is ,it requires
>> a
>> QFileInfo object and the file i want to show is on the server ,so i am
>> confused how to get the QFileInfo object for that file .
>>
>> is there any other way
>>
>>
>>> QFileIconProvider is probably what you are looking for:
>>> http://doc.trolltech.com/4.5/qfileiconprovider.html
>>>
>>> Jens
>>>
>>>
>>> "Puneet Bisht" <pbisht at nivio.com> wrote in message
>>> news:6977.192.168.5.2.1241097508.squirrel at webmail.nivio.com...
>>>> hi all,
>>>>
>>>> i m working on a ftp application.
>>>> i m showing files on a server using qlistwidget, now i want to set
>>>> icons
>>>> for files.
>>>> can anybody tell me how can i set system provided icons for a file
>>>> according to its extension e,g pdf,mp3 ...
>>>>
>>>> here i m using
>>>> item->setIcon(style()->standardIcon(QStyle::SP_DirIcon,0,this)); for
>>>> directories and
>>>> item->setIcon(style()->standardIcon(QStyle::SP_FileIcon,0,this)); for
>>>> file
>>>>
>>>> but i want to show different icons according to file extension.
>>>>
>>>> thanks in advance
>>>>
>>>> puneet
>>>
>>>
>>> --
>>> Jens Bache-Wiig - jbache at trolltech.com
>>>
>>> _______________________________________________
>>> Qt-interest mailing list
>>> Qt-interest at trolltech.com
>>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>>
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>
>
>
> --
> Tanguy Krotoff <tkrotoff at gmail.com>
> +33 6 68 42 70 24
>
More information about the Qt-interest-old
mailing list