Skip to content

Comments

Map Ctrl-Return to "OK" in many dialogs#66

Closed
lynn wants to merge 1 commit intojorio:masterfrom
lynn:lynn/ctrl-return
Closed

Map Ctrl-Return to "OK" in many dialogs#66
lynn wants to merge 1 commit intojorio:masterfrom
lynn:lynn/ctrl-return

Conversation

@lynn
Copy link
Contributor

@lynn lynn commented Sep 3, 2025

No description provided.

@jorio
Copy link
Owner

jorio commented Sep 3, 2025

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:

  • I'd prefer using Return instead of Ctrl+Return. Did you have a particular reason for choosing Ctrl+Return?

  • We could install the shortcut via a generic function that could look like this (e.g. in qtutils.py). This will give us a unified place to tweak it in the future if needed:

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)
  • Instead of patching each dialog individually, I think installing the shortcut from these 3 places ought to suffice:

    • RepoTask.flowDialog takes care of 90% of the dialogs and message boxes in the application
    • PrefsDialog
    • CloneDialog
  • One-off QMessageBoxes that don't go through RepoTask.flowDialog are typically simple enough that they already respond to Return out of the box.

@lynn
Copy link
Contributor Author

lynn commented Sep 4, 2025

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).

image

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.

@lynn lynn closed this Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants