The following doesn't work:
bool MainWindow::setActionIcon(QAction *theAction, QString const &iconName, QString const &backupTheme) // Try to set theAction's icon from the iconName in the system icon theme. // If the iconName isn't found in the system theme, try the backupTheme. // Return true iff the icon was set. // This doesn't work because setting the theme name is dynamic! The last // theme set is the theme that's finally rendered. // ...trying to see what happens when we make a local QIcon to store the icon ... // that doesn't work either! { QString systemTheme = QIcon::themeName(); qDebug() << "iconName: " << iconName << "systemTheme: " << systemTheme << "backupTheme: " << backupTheme; if ( !systemTheme.isEmpty() && QIcon::hasThemeIcon(iconName) ) { QIcon theIcon = QIcon::fromTheme(iconName); theAction->setIcon(theIcon); qDebug() << "set system theme icon for " << iconName; return true; } if (!backupTheme.isEmpty()) { QIcon::setThemeName(backupTheme); if (QIcon::hasThemeIcon(iconName)) { QIcon theIcon = QIcon::fromTheme(iconName); theAction->setIcon(theIcon); qDebug() << "Haz backup icon"; } QIcon::setThemeName(systemTheme); qDebug() << "set backup theme icon for " << iconName; return true; } qDebug() << "did not set icon for " << iconName; return false; }