简体   繁体   中英

PyQt: ReturnPressed method on a lineEdit is connecting to the wrong button

I have a lineEdit and three buttons; next, back and finish. If the user presses enter whilst the focus is on the lineEdit, I want it to be the same as pressing next. This is my code in the init method:

    self.clfdlg.lineEdit.returnPressed.connect(lambda: self.clfdlg.next.click())
    self.clfdlg.next.clicked.connect(lambda: self.next())   
    self.clfdlg.back.clicked.connect(lambda: self.back())
    self.clfdlg.finish.clicked.connect(lambda: self.finish())

Instead of the next() method being called, the finish() method is being called. I have also tried:

    self.clfdlg.lineEdit.returnPressed.connect(lambda: self.next())

This has the same result of calling the finish() method. Has this happened to anyone before, I'd really appreciate some advise as to where I am going wrong.

Thanks

If clfdlg is a QDialog , you're probably falling foul of the default property of the buttons. Try explicitly clearing this property on all the relevant buttons:

    self.clfdlg.next.setAutoDefault(False)
    self.clfdlg.next.setDefault(False)
    self.clfdlg.back.setAutoDefault(False)
    # etc ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM