I'm writing a GUI that analysis CSV files and I want to implement a function where the row will be deleted only when the whole row is selected. My current problem is when I select a cell and hit backspace, the row in which the selected cell located will be deleted as well. how do I prevent this?
from GUI import Ui_MainWindow
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.Qt import Qt
from PyQt5.QtCore import QItemSelectionModel
from PyQt5.QtWidgets import (QApplication,QMainWindow,QFileDialog,QTableWidget,
QMessageBox,QTableWidgetItem,QHeaderView)
class mainForm(QMainWindow,Ui_MainWindow):
def __init__(self, *args, **kwargs):
QMainWindow.__init__(self, *args, **kwargs)
self.setupUi(self)
self.initUI()
def keyPressEvent(self, event):
if event.key() == Qt.Key_Backspace:
self.removeRow()
def selectedRow(self):
if self.tabWidget.currentIndex() is 0 and self.inLoanTable.selectionModel().hasSelection():
row = self.inLoanTable.selectionModel().selectedIndexes()[0].row()
return int(row)
def removeRow(self):
if self.tabWidget.currentIndex() is 0 and self.inLoanTable.rowCount() > 0:
row = self.selectedRow()