Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Updating Icons after a QResource::registerResource()

    General and Desktop
    2
    2
    537
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      romulodefarias last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • First post
          Last post