Updating Icons after a QResource::registerResource()



  • I have a program that changes the resources file on the fly (QResource::registerResource()) successfully.

    The problem is that my icons aren't changing automatically.

    I've implemented a few solutions which work, but none of them seemed really good for me...

    Take a look:

    Solution 1
    It isn't a really bad solution, but it's so handmade for me. This project has a lot of Icons

    QPixmap pix(":/images/save");
    QIcon icon(pix);
    ui->myBtn->setIcon(icon);
    

    Solutuion 2
    Really bad, performance issues, also too handmade.

    QObject::disconnect(ui->myBtn, SIGNAL(clicked()), this, SLOT(changeResources()));
    ui->setupUi(this);
    QObject::connect(ui->myBtn, SIGNAL(clicked()), this, SLOT(changeResources()));
    

    --

    I thought calling the window's QWidget::update() method would do the job but unfortunately, no.

    Is there some smarter solution?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What about mimicking the language change system ? Create a new event type that you'll post when changing a resource and each widget that would like to update its icons can listen to that event and act accordingly.

    Hope it helps


Log in to reply