Conversation
|
Interesting! These already respond to the Return key by default in KDE Plasma (my primary target environment) and macOS, so I never ran into this issue during development. I just looked into this and, as it turns out, when Qt runs in other environments (GNOME, etc.), the Return key triggers any QCheckBox or QRadioButton that has keyboard focus. Hitting Return when a QLineEdit has focus does cause the QDialog to be accepted (as expected). In KDE, QCheckBox and QRadioButton can only be triggered with the Space key, not Return. I wonder if there's an "easy" way to get Qt to stick to this behavior in other environments? In the meantime, here are some thoughts about your approach:
def installDialogReturnShortcut(dialog: QDialog):
buttonBox = dialog.findChild(QDialogButtonBox)
if not buttonBox:
return
okButton = buttonBox.button(QDialogButtonBox.StandardButton.Ok)
if not okButton:
return
okButton.setShortcut(Qt.Key.Key_Return)
|
|
Hi @jorio! Yes, I made this change after realizing that in this dialog, neither Return nor Ctrl+Return accepted the dialog (I'm on GNOME).
I could tell that Return was activating the radio button, so I figured I should not override the "normal" behavior of Return. I wasn't aware that it was supposed to work. Also, I am used to pressing Ctrl+Return for this in Fork. (I think because Return writes a newline into the commit message box, for example, so I got used to Ctrl+Return for "accept/OK/push/commit/etc".) But actually, in most of these cases I am just as happy pressing Return to accept the dialog. Strange that KDE and Gnome differ here! I do wonder if there is a little switch we can flip somewhere in Qt to get it to work easily, but I can't find anything after a little bit of searching the web. I think the approach you outline is a much more reasonable way to handle this. I will make a new PR. |

No description provided.