mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
feat: qt_utils custom class for class where one can delete the row with backspace or delete
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
from .crosshair import Crosshair
|
from .crosshair import Crosshair
|
||||||
from .colors import Colors
|
from .colors import Colors
|
||||||
from .validator_delegate import DoubleValidationDelegate
|
from .validator_delegate import DoubleValidationDelegate
|
||||||
|
from .bec_table import BECTable
|
||||||
|
20
bec_widgets/qt_utils/bec_table.py
Normal file
20
bec_widgets/qt_utils/bec_table.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from PyQt5.QtWidgets import QTableWidget
|
||||||
|
from PyQt5.QtCore import Qt
|
||||||
|
|
||||||
|
|
||||||
|
class BECTable(QTableWidget):
|
||||||
|
"""Table widget with custom keyPressEvent to delete rows with backspace or delete key"""
|
||||||
|
|
||||||
|
def keyPressEvent(self, event) -> None:
|
||||||
|
"""
|
||||||
|
Delete selected rows with backspace or delete key
|
||||||
|
Args:
|
||||||
|
event: keyPressEvent
|
||||||
|
"""
|
||||||
|
if event.key() in (Qt.Key_Backspace, Qt.Key_Delete):
|
||||||
|
selected_ranges = self.selectedRanges()
|
||||||
|
for selected_range in selected_ranges:
|
||||||
|
for row in range(selected_range.topRow(), selected_range.bottomRow() + 1):
|
||||||
|
self.removeRow(row)
|
||||||
|
else:
|
||||||
|
super().keyPressEvent(event)
|
@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt
|
from bec_widgets.qt_utils import BECTable
|
||||||
from PyQt5 import uic
|
from PyQt5 import uic
|
||||||
from PyQt5.QtCore import pyqtSignal
|
from PyQt5.QtCore import pyqtSignal
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
|
@ -106,7 +106,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableWidget" name="tableWidget_y_signals">
|
<widget class="BECTable" name="tableWidget_y_signals">
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Name</string>
|
<string>Name</string>
|
||||||
@ -159,6 +159,13 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>BECTable</class>
|
||||||
|
<extends>QTableWidget</extends>
|
||||||
|
<header>bec_widgets.qt_utils.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
Reference in New Issue
Block a user