From QLineEdit, if I press :
Ctrl + S, it works fine
But at the same time, if I press Alt + C, or Shift+S (as per my code)
Event filter works fine, but at the same time QLineEdit Box Updated with that Pressing key.
For example if I press Alt+C from QLineEdit, the Letter "C" updated/appeared in my QLineEdit and Press Shift+S, In QLineEdit, the letter "S" is updated/appeared.
How to avoid it ?
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class textbox_keypress(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("List Box Example")
self.mydesign()
# ----------------------------------------------------------------------------------
def mydesign(self):
self.textbox = QLineEdit(self)
self.textbox.setGeometry(10,10,300,30)
self.textbox.installEventFilter(self)
def eventFilter(self, source, event):
if event.type() == QEvent.KeyPress and source is self.textbox:
if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_S:
print("Control + S")
if event.key() == Qt.Key_C and event.modifiers() == Qt.AltModifier:
print("Alt + C")
if event.key() == Qt.Key_E and event.modifiers() == Qt.ShiftModifier:
print("Shift + E ")
return super(textbox_keypress, self).eventFilter(source,event)
# ----------------------------------------------------------------------------------
def main():
myapp = QApplication(sys.argv)
mywindow = textbox_keypress()
mywindow.show()
sys.exit(myapp.exec_())
if __name__ =="__main__":
main()