How to check the value of KeyboardModifiers?
-
Hi,
I am using QMenu and inside the keyPressEvent I check the event.modifiers(), but how can I know which modifiers are active from this returned value?
Do I have to check all combinations of ctrl, alt and shift? Though I tried this:
(event.modifiers() == QtCore.Qt.ControlModifier | QtCore.Qt.AltModifier | QtCore.Qt.ShiftModifier)and it returns False, when all of these keys were active.
I just want to check like this if possible:
if event.modifiers().IsCtrlActive()
append(mods, "C")
if event.modifiers().IsShiftActive()
append(mods, "S")
...Thanks a lot.
-
Hi,
I am using QMenu and inside the keyPressEvent I check the event.modifiers(), but how can I know which modifiers are active from this returned value?
Do I have to check all combinations of ctrl, alt and shift? Though I tried this:
(event.modifiers() == QtCore.Qt.ControlModifier | QtCore.Qt.AltModifier | QtCore.Qt.ShiftModifier)and it returns False, when all of these keys were active.
I just want to check like this if possible:
if event.modifiers().IsCtrlActive()
append(mods, "C")
if event.modifiers().IsShiftActive()
append(mods, "S")
...Thanks a lot.
@lachdanan said in How to check the value of KeyboardModifiers?:
(event.modifiers() == QtCore.Qt.ControlModifier | QtCore.Qt.AltModifier | QtCore.Qt.ShiftModifier)
This is not how it works.
If you want to check whether all modifiers are set:(event.modifiers() & QtCore.Qt.ControlModifier) && (event.modifiers() & QtCore.Qt.AltModifier) && (event.modifiers() & QtCore.Qt.ShiftModifier)
-
@jsulm said in How to check the value of KeyboardModifiers?:
(event.modifiers() & QtCore.Qt.ControlModifier)
Thanks so basically I can just do?:
if (event.modifiers() & QtCore.Qt.ControlModifier):
print "there is Ctrl in the current modifiers, not necessarily only Ctrl" -
@jsulm said in How to check the value of KeyboardModifiers?:
(event.modifiers() & QtCore.Qt.ControlModifier)
Thanks so basically I can just do?:
if (event.modifiers() & QtCore.Qt.ControlModifier):
print "there is Ctrl in the current modifiers, not necessarily only Ctrl"@lachdanan Yes, this is how bitwise operators work: https://www.geeksforgeeks.org/bitwise-operators-in-c-cpp/
-
Maybe this works on PySide6:
if int(modifiers) & Qt.KeyboardModifier.ControlModifier: print("ctrl")
-
Maybe this works on PySide6:
if int(modifiers) & Qt.KeyboardModifier.ControlModifier: print("ctrl")
After 4 years?!?! what's the point of making the same suggestion again?