Answer the question
In order to leave comments, you need to log in
How to intercept arrow clicks in PyQt?
I need to intercept arrow clicks in a QTextEdit. How to do it? We need to intercept the shooters. I tried to make a global interception of the KeyPress event, but for some reason the arrows are not intercepted.
Answer the question
In order to leave comments, you need to log in
here, catch the scraps of the working code:
.....
self.keymap=
{Qt.Key_Left: _board.tryLeft,
Qt.Key_Right: _board.tryRight,
Qt.Key_Up: _board.tryRorateCCW,
Qt.Key_Down: _board.tryRorateCCW,
Qt.Key_Space: _board.dropDown,
Qt.Key_D: _board.tryLineDown}
........
def keyPressEvent(self, event):
key = event.key()
if key == Qt.Key_Escape:
self.paused ^= True
elif not self.paused and key in self.keymap:
self.keymap[key]()
else:
super(Tetris, self).keyPressEvent(event)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question