PyQt Connect to KeyPressEvent

前端 未结 2 509
情书的邮戳
情书的邮戳 2020-12-03 15:06

Certain widgets will allow me to do:

self.widget.clicked.connect(on_click)

but doing:

self.widget.keyPressEvent.connect(on_         


        
2条回答
  •  醉酒成梦
    2020-12-03 15:42

    The way I've done this in the past is (it is a work around), where this is in the sender and the receiver declares/connects to the signal.

    def keyPressEvent(self, event):
        if type(event) == QtGui.QKeyEvent:
            if event.key() == QtCore.Qt.Key_Space:
                self.emit(QtCore.SIGNAL('MYSIGNAL'))
    

提交回复
热议问题