最近项目需要用到一些关于系统的文件图标,找了一通Qt文档,找到了提供系统文件图标的类
QFileIconProvider
,不用在网上找了。
QFileIconProvider提供的图标共有七个(电脑,桌面,回收站,网络,磁盘驱动器,文件)。
使用例子:
代码语言:javascript复制#include <QApplication>
#include <QFileIconProvider>
#include <QHBoxLayout>
#include <QPushButton>
#include <QWidget>
int main(int argc, char **argv)
{
QApplication a(argc, argv);
/*
QFileIconProvider::Computer
QFileIconProvider::Desktop
QFileIconProvider::Trashcan
QFileIconProvider::Network
QFileIconProvider::Drive
QFileIconProvider::Folder
QFileIconProvider::File
*/
QFileIconProvider fileIconProvider;
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->addWidget(new QPushButton(fileIconProvider.icon(QFileIconProvider::Computer), "Computer"));
hLayout->addWidget(new QPushButton(fileIconProvider.icon(QFileIconProvider::Desktop), "Desktop"));
hLayout->addWidget(new QPushButton(fileIconProvider.icon(QFileIconProvider::Trashcan), "Trashcan"));
hLayout->addWidget(new QPushButton(fileIconProvider.icon(QFileIconProvider::Network), "Network"));
hLayout->addWidget(new QPushButton(fileIconProvider.icon(QFileIconProvider::Drive), "Drive"));
hLayout->addWidget(new QPushButton(fileIconProvider.icon(QFileIconProvider::Folder), "Folder"));
hLayout->addWidget(new QPushButton(fileIconProvider.icon(QFileIconProvider::File), "File"));
QWidget w;
w.setLayout(hLayout);
w.show();
return a.exec();
}