[Widgets] Prevent double-delete of settings popup content on size adjustment

Co-authored-by: sentry[bot] <39604003+sentry[bot]@users.noreply.github.com>
This commit is contained in:
Lukas Brübach 2026-11-10 09:43:05 +00:00
parent f089414f1c
commit 88d0bc4098

View file

@ -66,15 +66,24 @@ void SettingsPopupWidget::adjustSizeToFitScreen()
resize(sizeHint().width(), maxHeight); // Ensure content width is kept intact resize(sizeHint().width(), maxHeight); // Ensure content width is kept intact
// Add scrollArea to layout if not already added // 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); layout->addWidget(scrollArea);
} }
// Set the scroll area widget // Set the scroll area widget; it takes ownership of containerWidget until handed back above
scrollArea->setWidget(containerWidget); if (scrollArea->widget() != containerWidget) {
layout->removeWidget(containerWidget);
scrollArea->setWidget(containerWidget);
}
} else { } 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) {
if (scrollArea->widget() == containerWidget) {
scrollArea->takeWidget();
containerWidget->setParent(this);
}
layout->removeWidget(scrollArea); layout->removeWidget(scrollArea);
delete scrollArea; delete scrollArea;
scrollArea = nullptr; // Reset the pointer scrollArea = nullptr; // Reset the pointer
@ -82,7 +91,10 @@ void SettingsPopupWidget::adjustSizeToFitScreen()
// Set the containerWidget directly without scrollArea and adjust its height // Set the containerWidget directly without scrollArea and adjust its height
resize(sizeHint().width(), contentHeight); // Resize the widget based on content 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 // Ensure layout updates after changes