My aim to deactivate the checkbox, if my textbox is empty. So I try with the following code if I clear my entire textbox by the way of "select all characters" using Ctrl+A and delete it. But in my code, the first part only worked, that is Ctrl+A, If I press the Delete key that is the second part of my code is not worked, How to rectify?
if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_A :
print("I am inside of Cntrl+A")
if event.key() == Qt.Key_Delete:
print("i Am inside of key_delete")
self.checkbox.setChecked(False)
self.checkstatus = 0
return True
Minimal reproducible Code
import os
from PyQt5.QtWidgets import QCheckBox,QLineEdit,QWidget,QApplication,QVBoxLayout
from PyQt5.QtCore import QEvent,Qt
class CtrlaDel(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Key Press Event")
self.le = QLineEdit()
self.cb = QCheckBox()
self.cb.setChecked(True)
self.vbox = QVBoxLayout(self)
self.vbox.addWidget(self.le)
self.vbox.addWidget(self.cb)
self.le.installEventFilter(self)
def eventFilter(self, source, event):
if event.type() == QEvent.KeyPress and source is self.le:
print("ddddsdsdsdsdsdsds")
if event.key() == Qt.Key_Backspace or event.key() == Qt.Key_Delete and source is self.le:
print("ddd")
if len(self.le.text()) <= 1:
self.cb.setChecked(False)
if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_A:
print("I am inside of Ctrl+A")
if event.key() == Qt.Key_Delete:
print("I am Inside of Delete")
self.cb.setChecked(False)
self.checkstatus = 0
return True
return super(CtrlaDel, self).eventFilter(source, event)
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
mainwindow = CtrlaDel()
mainwindow.show()
sys.exit(app.exec_())
A, how could it also beDeletein the nextifblock?