key binding shift + Tab not working
-
then the focus should go to next text box
modifiers = QtGui.QApplication.keyboardModifiers()if ((modifiers & QtCore.Qt.ShiftModifier) and (event.key() == QtCore.Qt.Key_Tab)): -----> for Shift + key_tab
print("\n I am here in shift Modifies shift + Tab")
return
QtGui.QTextBrowser.keyPressEvent(self, event)
I am not able to get print print("\n I am here in shift Modifies shift + Tab"
Why any reason ?
Could you suggest correct
-
@Qt-Enthusiast said in key binding shift + Tab not working:
modifiers = QtGui.QApplication.keyboardModifiers()
? What is that?!
You need to get the modifiers from https://doc.qt.io/qt-5/qkeyevent.html#modifiers from the event parameter. -
modifiers = event.modifiers()
event if I do this it does not work
-
@Qt-Enthusiast Does the widget where you have your keyPressEvent has focus when you press Shift-Tab?
-
@Qt-Enthusiast Please read: https://doc.qt.io/qt-5/qwidget.html#event
"Key press and release events are treated differently from other events. event() checks for Tab and Shift+Tab and tries to move the focus appropriately. If there is no widget to move the focus to (or the key press is not Tab or Shift+Tab), event() calls keyPressEvent()."So, you need to override https://doc.qt.io/qt-5/qwidget.html#event if you want to react on Tab or Shift-Tab.