Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6784737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:02:00+00:00 2026-05-26T17:02:00+00:00

My foremost question is: How do I set/change the file icon in a QFileInfo

  • 0
  • My foremost question is:

How do I set/change the file icon in a QFileInfo object?
If you look at my code, Qlist<QFileInfo> lists the icon of all my folders in my home directory as gnome-fs-directory. Which means, QFileInfo lists even my desktop folder’s icon as plain gnome-fs-directory.

But I want Desktop to have QFileIconProvider::Desktop as icon.

  • Which consequently leads to the 2nd question:

Is QFileInfo the appropriate class to use to find out the icon that QFileSystemModel would use?

  • Which leads to the 3rd question:

Why did my QDir not pass QFileSystemModel a QFileInfo list with the appropriate icon role for Desktop?

  • So the ultimate question is, what do I have to do to ensure QFileSystemModel uses the appropriate icon role, when listing itself in a tree view or list view?

Code to find out the file icon of each folder in the home folder:

void MainWindow::fileIconInfo(QFileSystemModel *model)
{
    QFileIconProvider *iconprov = model->iconProvider();

    QFileInfoList fileInfoList = QDir::home().entryInfoList();
    QFileInfoList::Iterator i;

    foreach (QFileInfo fi, fileInfoList){

        if (fi.fileName() == QString("Desktop"))
            /*change the icon to QFileIconProvider::Desktop*/;

        //the following line indicates all my icons are gnome-fs-directory!!*/
        std::cout << iconprov->icon(fi).name().toStdString() << std::endl;
    }
}

This is my main window:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    fileSystemTree(ui->listView);
    fileSystemTree(ui->treeView);
}

Setting the model for the view:

void MainWindow::fileSystemTree(QAbstractItemView *view) {
    QFileSystemModel *model = new QFileSystemModel;
    model->setRootPath(QDir::homePath());

    view->setModel(model);
    view->setRootIndex(model->index(QDir::homePath()));

    fileIconInfo(model);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:02:01+00:00Added an answer on May 26, 2026 at 5:02 pm

    I think what you are describing is caused by the fact that QFileIconProvider is detecting that you use Gnome, and the is using Gtk style – no matter what. Could you try to start some other desktop environment and see if problem remains? If it does then I am right and only thing you can do is to subclass QFileSystemModel and change QIcon returned from data method – but this is quite crude and non-flexible solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First and foremost, thank you all for reading this and helping, I'm very grateful.
I am first and foremost a perl coder, but like many, also code in
First and foremost, I'm so sorry about how long this question is and appreciate
First and foremost-- I have a file of strings. The smallest file is about
Please no jQuery code, as I want to learn javascript first and foremost. I
First and foremost, I apologize for any vagueness in this question. At this point,
THE EXAMPLE First and foremost, here's my code and problem: http://www.nathanstpierre.com/MBX/showoff.html THE ISSUE So
Preface: Hi, all! Here goes. First and foremost, I am not familiar with jquery,
First and foremost, I've been learning JS for about 2-3 hours. I've lost track.
Ok, so my previous question did not produce any useful answers, so I'll try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.