From b6136bc8ce402621ed8daaaff86958da16672cd4 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Sat, 29 Jul 2023 18:47:15 +0200 Subject: [PATCH] subclass QTableWidget for change multiple checkstates --- src/gui_qt/fit/fit_forms.py | 3 ++- src/gui_qt/lib/tables.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/gui_qt/fit/fit_forms.py b/src/gui_qt/fit/fit_forms.py index 0ef0591..ed215cf 100644 --- a/src/gui_qt/fit/fit_forms.py +++ b/src/gui_qt/fit/fit_forms.py @@ -6,6 +6,7 @@ from ..Qt import QtCore, QtWidgets, QtGui from .._py.fitmodelwidget import Ui_FitParameter from .._py.save_fitmodel_dialog import Ui_SaveDialog from ..lib.iconloading import get_icon +from ..lib.tables import TableWidget class FitModelWidget(QtWidgets.QWidget, Ui_FitParameter): @@ -364,7 +365,7 @@ class FitModelTree(QtWidgets.QTreeWidget): return funcs -class FitTableWidget(QtWidgets.QTableWidget): +class FitTableWidget(TableWidget): def __init__(self, parent=None): super().__init__(parent=parent) diff --git a/src/gui_qt/lib/tables.py b/src/gui_qt/lib/tables.py index 15195c4..a7b6ef1 100644 --- a/src/gui_qt/lib/tables.py +++ b/src/gui_qt/lib/tables.py @@ -28,4 +28,17 @@ class TreeWidget(QtWidgets.QTreeWidget): continue it.setCheckState(0, QtCore.Qt.Unchecked if it.checkState(0) == QtCore.Qt.Checked else QtCore.Qt.Checked) else: - super().keyPressEvent(evt) \ No newline at end of file + super().keyPressEvent(evt) + + +class TableWidget(QtWidgets.QTableWidget): + def keyPressEvent(self, evt: QtGui.QKeyEvent): + if evt.key() == QtCore.Qt.Key.Key_Space: + for idx in self.selectedIndexes(): + item = self.itemFromIndex(idx) + cs = item.checkState() + item.setCheckState(QtCore.Qt.CheckState.Unchecked if cs == QtCore.Qt.CheckState.Checked + else QtCore.Qt.CheckState.Checked) + else: + super().keyPressEvent(evt) +