From 88d0bc4098bed82d619f882a9194ce5eccdf292f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= <44814898+BruebachL@users.noreply.github.com> Date: Tue, 10 Nov 2026 09:43:05 +0000 Subject: [PATCH] [Widgets] Prevent double-delete of settings popup content on size adjustment Co-authored-by: sentry[bot] <39604003+sentry[bot]@users.noreply.github.com> --- .../quick_settings/settings_popup_widget.cpp | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/cockatrice/src/interface/widgets/quick_settings/settings_popup_widget.cpp b/cockatrice/src/interface/widgets/quick_settings/settings_popup_widget.cpp index 351e3732c..db0f2b81e 100644 --- a/cockatrice/src/interface/widgets/quick_settings/settings_popup_widget.cpp +++ b/cockatrice/src/interface/widgets/quick_settings/settings_popup_widget.cpp @@ -66,15 +66,24 @@ void SettingsPopupWidget::adjustSizeToFitScreen() resize(sizeHint().width(), maxHeight); // Ensure content width is kept intact // Add scrollArea to layout if not already added - if (layout->count() == 1) { // We only have one widget (containerWidget) at the start + if (layout->indexOf(scrollArea) == -1) { layout->addWidget(scrollArea); } - // Set the scroll area widget - scrollArea->setWidget(containerWidget); + // Set the scroll area widget; it takes ownership of containerWidget until handed back above + if (scrollArea->widget() != containerWidget) { + layout->removeWidget(containerWidget); + scrollArea->setWidget(containerWidget); + } } else { - // If the scroll area exists, remove it + // If the scroll area exists, remove it. QScrollArea owns the widget set on it and would + // delete containerWidget (and every settings widget inside it) along with itself, so take + // the container back before deleting the scroll area. if (scrollArea) { + if (scrollArea->widget() == containerWidget) { + scrollArea->takeWidget(); + containerWidget->setParent(this); + } layout->removeWidget(scrollArea); delete scrollArea; scrollArea = nullptr; // Reset the pointer @@ -82,7 +91,10 @@ void SettingsPopupWidget::adjustSizeToFitScreen() // Set the containerWidget directly without scrollArea and adjust its height resize(sizeHint().width(), contentHeight); // Resize the widget based on content height - layout->addWidget(containerWidget); // Re-add the containerWidget without scroll area + if (layout->indexOf(containerWidget) == -1) { + layout->addWidget(containerWidget); // Re-add the containerWidget without scroll area + } + containerWidget->show(); } // Ensure layout updates after changes