diff --git a/portprotonqt/game_library_manager.py b/portprotonqt/game_library_manager.py index be36edd..1213aac 100644 --- a/portprotonqt/game_library_manager.py +++ b/portprotonqt/game_library_manager.py @@ -505,17 +505,25 @@ class GameLibraryManager: """Clears all widgets from the layout.""" if layout is None: return + # Remove all widgets from the layout and clean up caches while layout.count(): child = layout.takeAt(0) if child.widget(): widget = child.widget() + # Clean up cache if widget exists in it for key, card in list(self.game_card_cache.items()): if card == widget: del self.game_card_cache[key] if key in self.pending_images: del self.pending_images[key] + break + # Always schedule widget for deletion regardless of cache state widget.deleteLater() + # Also clear the cache completely if needed (in case layout wasn't in sync) + self.game_card_cache.clear() + self.pending_images.clear() + def set_games(self, games: list[tuple]): """Sets the games list and updates the filtered games.""" self.games = games diff --git a/portprotonqt/main_window.py b/portprotonqt/main_window.py index ac51736..43319bf 100644 --- a/portprotonqt/main_window.py +++ b/portprotonqt/main_window.py @@ -1199,7 +1199,7 @@ class MainWindow(QMainWindow): self.progress_bar.setRange(0, 0) # Indeterminate self.update_status_message.emit(_("Refreshing game library..."), 0) - # Clear the game card cache to force reload of custom data + # Clear the game card cache and layout to force reload of custom data if hasattr(self, 'game_library_manager') and self.game_library_manager: # Clear the cache to ensure custom data is reloaded self.game_library_manager.game_card_cache.clear() @@ -1209,6 +1209,19 @@ class MainWindow(QMainWindow): # Mark for full rebuild of search indices self.game_library_manager.dirty = True # Force full update + # Also clear the layout to ensure old widgets are removed + if (hasattr(self.game_library_manager, 'gamesListLayout') and + self.game_library_manager.gamesListLayout and + hasattr(self.game_library_manager, 'gamesListWidget') and + self.game_library_manager.gamesListWidget): + # Remove all widgets from the layout + self.game_library_manager.clear_layout(self.game_library_manager.gamesListLayout) + + # Force layout update to ensure UI changes are visible + self.game_library_manager.gamesListWidget.updateGeometry() + if hasattr(self.game_library_manager, 'gamesListLayout'): + self.game_library_manager.gamesListLayout.update() + # Reload games using the existing loadGames functionality # Use a small delay to allow UI to update before starting the refresh QTimer.singleShot(50, lambda: self.loadGames())