From 70bf22d6cae0f0a59a8d9cf19d55bd7c19fffe6d Mon Sep 17 00:00:00 2001 From: jolavillette Date: Fri, 2 Jan 2026 23:39:12 +0100 Subject: [PATCH] possibly fix window reopening issues --- .../src/gui/statistics/StatisticsWindow.cpp | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/retroshare-gui/src/gui/statistics/StatisticsWindow.cpp b/retroshare-gui/src/gui/statistics/StatisticsWindow.cpp index ff15eed31..d72df73e7 100644 --- a/retroshare-gui/src/gui/statistics/StatisticsWindow.cpp +++ b/retroshare-gui/src/gui/statistics/StatisticsWindow.cpp @@ -74,8 +74,14 @@ void StatisticsWindow::showYourself() mInstance = new StatisticsWindow(); } + /* Ensure the window is visible and restored if minimized */ + if (mInstance->isMinimized()) { + mInstance->showNormal(); + } + mInstance->show(); - mInstance->activateWindow(); + mInstance->raise(); /* Bring to front */ + mInstance->activateWindow(); /* Give focus */ } StatisticsWindow* StatisticsWindow::getInstance() @@ -93,22 +99,26 @@ void StatisticsWindow::releaseInstance() /********************************************** STATIC WINDOW *************************************/ - StatisticsWindow::StatisticsWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::StatisticsWindow) { ui->setupUi(this); - Settings->loadWidgetInformation(this); - + /* Automatically destroy the object when the window is closed */ + setAttribute(Qt::WA_DeleteOnClose); + + Settings->loadWidgetInformation(this); + initStackedPage(); connect(ui->stackPages, SIGNAL(currentChanged(int)), this, SLOT(setNewPage(int))); ui->stackPages->setCurrentIndex(0); - int toolSize = Settings->getToolButtonSize(); - ui->toolBar->setToolButtonStyle(Settings->getToolButtonStyle()); - ui->toolBar->setIconSize(QSize(toolSize,toolSize)); - setWindowTitle("RetroShare Statistics - " + MainWindow::getInstance()->get_nameAndLocation()); + + int toolSize = Settings->getToolButtonSize(); + ui->toolBar->setToolButtonStyle(Settings->getToolButtonStyle()); + ui->toolBar->setIconSize(QSize(toolSize,toolSize)); + + setWindowTitle("RetroShare Statistics - " + MainWindow::getInstance()->get_nameAndLocation()); } StatisticsWindow::~StatisticsWindow() @@ -233,8 +243,11 @@ void StatisticsWindow::setNewPage(int page) void StatisticsWindow::keyPressEvent(QKeyEvent *event) { if (event->key() == Qt::Key_Escape) { - close(); // Close window is escape is pressed + /* This will trigger the closeEvent and, thanks to WA_DeleteOnClose, the destructor */ + close(); } else { + /* Pass the event to the base class for default handling */ QMainWindow::keyPressEvent(event); } } +