0
votes

The dialog window has three widgets: QComboBox, QLineEdit and QPushButton. When dialog is shown the QLineEdit is being set as "current" by default. Any keyboard entry performed will be entered straight into QLineEdit field.

Instead of QLineEdit I want QPushButton to be current. So the user could hit a keyboard "Enter" key to trigger the function connected to QPushButton. What flag or attribute of QPushButton needs to be set to achieve this?

2
At a wild guess you could try changing the tab order, or fiddle with focus, e.g. setFocusPolicy to prevent that widget automatically gaining focus.all or None
You can try to change the initialization order. Or setTabOrder(widget1, widget2)0rko

2 Answers

2
votes

If you are using QtDesigner, with QPushButton selected go to Property Editor and scroll to the bottom, set the Default property checked OR inside your code, button.setDefault(True), this feature is specially for what you are looking for. Look here for details.

0
votes

I suppose, You want to use eventFilter() to handle keyPressEvent(). Then You only need

    self.pushButton.setFocus()

in QDialog's constructor and install an appropriate eventFilter on pushButton