Please nominate your Qt Champions for 2021! https://forum.qt.io/topic/132134/looking-for-the-2021-qt-champions
Updating Icons after a QResource::registerResource()
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:
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);
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?
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