Reimplement the reject slot for the parent dialog class

This commit is contained in:
Veronica Berglyd Olsen
2024-06-10 01:02:48 +02:00
parent cddf63f111
commit f8c1ee90ce
+7 -7
View File
@@ -30,8 +30,8 @@ from __future__ import annotations
from enum import Enum from enum import Enum
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from PyQt5.QtCore import QSize, Qt from PyQt5.QtCore import QSize, Qt, pyqtSlot
from PyQt5.QtGui import QKeyEvent, QKeySequence, QWheelEvent from PyQt5.QtGui import QWheelEvent
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QApplication, QComboBox, QDialog, QDoubleSpinBox, QSpinBox, QToolButton, QApplication, QComboBox, QDialog, QDoubleSpinBox, QSpinBox, QToolButton,
QWidget QWidget
@@ -54,11 +54,11 @@ class NDialog(QDialog):
self.setParent(None) # type: ignore self.setParent(None) # type: ignore
return return
def keyPressEvent(self, event: QKeyEvent) -> None: @pyqtSlot()
"""Overload keyPressEvent and forward escape to close.""" def reject(self) -> None:
if event.matches(QKeySequence.StandardKey.Cancel): """Overload the reject slot and also call close."""
self.close() super().reject()
event.ignore() self.close()
return return