Where is the connect() method in PyQt5?

前端 未结 2 1266
梦谈多话
梦谈多话 2021-01-04 11:53

I\'m following Mark Summerfield\'s Rapid GUI Programming with Python and Qt which is using PyQt4. I\'d prefer to be working with PyQt5, but I have both on my ma

相关标签:
2条回答
  • 2021-01-04 12:20

    You are using old-style signals and slots which have not been implemented in PyQt5. Try using new-style signals and slots.

    self.lineedit.returnPressed.connect(self.updateUi)
    
    0 讨论(0)
  • 2021-01-04 12:20

    Another answer is to add keyPressEvent() method to capture keyboards events.

    It will call your updateUi() method when the correct key is pressed.

    def keyPressEvent(self, event):
        key = event.key()
        if key == Qt.Key_Enter:
            #For Enter of keyboard number
            print("key Enter press")
            self.updateUi()
        if key == Qt.Key_Return:
            #For Enter of keyboard
            print("key Enter press")
            self.updateUi()
    
    0 讨论(0)
提交回复
热议问题