override the keyPressEvent function, enabling the statistics window to close when the Escape key is pressed

This commit is contained in:
jolavillette 2025-12-31 07:23:22 +01:00
parent a17699e166
commit 0bca0d3b27
2 changed files with 12 additions and 1 deletions

View file

@ -23,6 +23,7 @@
#include <QTimer>
#include <QDateTime>
#include <QActionGroup>
#include <QKeyEvent>
#include <algorithm>
#include <iostream>
@ -228,3 +229,12 @@ void StatisticsWindow::setNewPage(int page)
ui->stackPages->setCurrentIndex(page);
}
}
void StatisticsWindow::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Escape) {
close(); // Close window is escape is pressed
} else {
QMainWindow::keyPressEvent(event);
}
}

View file

@ -66,7 +66,8 @@ public slots:
protected:
void changeEvent(QEvent *e);
void closeEvent (QCloseEvent * event);
void closeEvent (QCloseEvent * event);
void keyPressEvent(QKeyEvent *event) override;
private:
void initStackedPage();