Search code examples
c++qtqstyle

Should I fetch standard icons from QFileIconProvider or QStyle?


Both classes offer standard icons for folders and files. Which one should I use? Are they guaranteed to be the same?


Solution

  • Qt does not strictly guarantee that... In the current implementation, however, QFileIconProvider is a shorthand for using the style. That's unlikely to change soon and it's very logical to do so... Therefore, I stop nitpicking: Yes, it is guaranteed.

    Qt is open source so just have a look at the sources: https://github.com/qt/qtbase/blob/dev/src/widgets/itemviews/qfileiconprovider.cpp. There you have

    QIcon QFileIconProvider::icon(IconType type) const
    {
        Q_D(const QFileIconProvider);
        switch (type) {
        case Computer:
            return d->getIcon(QStyle::SP_ComputerIcon);
    //....
    QIcon QFileIconProviderPrivate::getIcon(QStyle::StandardPixmap name) const
    {
        switch (name) {
        case QStyle::SP_ComputerIcon:
            if (computer.isNull())
                computer = QApplication::style()->standardIcon(name);
            return computer;
    //...