Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Updating Icons after a QResource::registerResource()
Forum Updated to NodeBB v4.3 + New Features

Updating Icons after a QResource::registerResource()

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 711 Views 2 Watching
  • 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 Offline
    R Offline
    romulodefarias
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved