nmreval/src/gui_qt/lib/listwidget.py
Dominik Demuth 6b71de8265 bug-fixer (#40)
fixes #32, #34, #39

Co-authored-by: Dominik Demuth <dominik.demuth@physik.tu-darmstadt.de>
Reviewed-on: #40
2023-04-07 13:45:28 +00:00

21 lines
750 B
Python

from ..Qt import QtWidgets, QtGui, QtCore
class QListWidgetSelect(QtWidgets.QListWidget):
"""
Extension of QListWidget to change the check state of all selected QListWidgetItems with space key
"""
def __init__(self, parent=None):
super().__init__(parent=parent)
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)