Repository: spyder-ide/spyder

Issue:
Alt+Space shortcut cannot be set in Spyder 4
Moved to Spyder 4 RC2 - awesome work guys! The dark theme is super slick!

I miss something from previouos Spyders  though - I cannot set the `Alt+Space` shortcut anymore. I had this for delete line (and have it in all my other editors). 

So if it's fixable I would appreciate if you can bring it back : )


Discussion:
Ok, we'll take a look at it in the future.
Please see https://github.com/spyder-ide/spyder/issues/7981, it is closely related to the issue reported here.
Also, @gerazov, what is your operating system? Thanks!
Yeah, I saw #7981 but most of it was about Emacs support, I just wanted my shortcut back :smile: 
I'm on Manjaro 18.1.2 with KDE running on kernel 5.3.8-3. 
> Yeah, I saw #7981 but most of it was about Emacs support, I just wanted my shortcut back 😄
> I'm on Manjaro 18.1.2 with KDE running on kernel 5.3.8-3.

What happens when you try to set the shortcut with `Alt + Space`?
Nothing happens - like I didn't press anything, but `Alt+x` gets registered fine.
Hey, I'm having the same issue using Ubuntu 18.04
@FabianHofmann, those kind of comments are not helpful. For next time please leave an emoji reaction on the issue description.
> 
> Nothing happens - like I didn't press anything, but `Alt+x` gets registered fine.

Ok thanks. I don't understand why it is not registered because we are not blocking it. So if the OS is not eating the event, it should be passed to the shortcut editor dialog. 

When you press `Alt + Space` in the Editor, is this registered as a normal space? Sorry, but I don't have access to your OS, so I'm trying to guess where the problem is from your inputs.

>Manjaro 18.1.2 with KDE running on kernel 5.3.8-3.

I could create a VM later and try to see what the issue is. On Mac `alt+space` is registered fine.
This is close enough, right?
https://osdn.net/projects/manjaro/storage/kde/18.1.3/manjaro-kde-18.1.3-191114-linux53.iso/ @gerazov ?
> 
> 
> > Manjaro 18.1.2 with KDE running on kernel 5.3.8-3.
> 
> I could create a VM later and try to see what the issue is. On Mac `alt+space` is registered fine.

Cool thanks! On Windows, I haven't found a way yet to override without some dirty hack the `open the window menu`  that is triggered by `Alt + Space`.
>without some dirty hack 

We will probably need to do this anyway even if to notify the user this is not a suitable shortcut on windows as it interferes with the OS
@jnsebgosselin yeah `Alt+space` adds spaces in the editor. KDE does define this is a shortcut to `krunner` but I've disabled that in the System Settings.

I have Spyder 3 still installed in a different `conda` environment and the shortcut is working fine and does register in the keyboard settings.

@goanpeca that's the one.
> 
> 
> @jnsebgosselin yeah `Alt+space` adds spaces in the editor. KDE does define this is a shortcut to `krunner` but I've disabled that in the System Settings.
> 
> I have Spyder 3 still installed in a different `conda` environment and the shortcut is working fine and does register in the keyboard settings.


Ok thanks, that is useful. I can reproduce this on Windows with `Ctrl+Space`.

I think I have found a way to fix that, I'll submit a PR.

Resolving patch:
diff --git a/spyder/preferences/shortcuts.py b/spyder/preferences/shortcuts.py
--- a/spyder/preferences/shortcuts.py
+++ b/spyder/preferences/shortcuts.py
@@ -291,7 +291,14 @@ def accept(self):
 
     def event(self, event):
         """Qt method override."""
-        if event.type() in (QEvent.Shortcut, QEvent.ShortcutOverride):
+        # We reroute all ShortcutOverride events to our keyPressEvent and block
+        # any KeyPress and Shortcut event. This allows to register default
+        # Qt shortcuts for which no key press event are emitted.
+        # See spyder-ide/spyder/issues/10786.
+        if event.type() == QEvent.ShortcutOverride:
+            self.keyPressEvent(event)
+            return True
+        elif event.type() in [QEvent.KeyPress, QEvent.Shortcut]:
             return True
         else:
             return super(ShortcutEditor, self).event(event)


Test patch: