Qt 5.4 Ctrl+Z shortcut conflict in Python? Doesn't work until its button has been pressed
Question: In Qt Designer 5.4, I have a QPushButton and have set its shortcut to
`Ctrl`+`Z`. I'm using pyuic5 to turn it into Python code. This is the
resulting line in the Python code:

    
    
    self.quickTextUndoButton.setShortcut(_translate("newEntryDialog", "Ctrl+Z"))
    

When running the application, pressing `Ctrl`+`Z` does not call the slot as
expected, until the QPushButton has been pressed (which does call the slot);
thereafter, pressing `Ctrl`+`Z` DOES call the slot as expected.

This 'initializing' behavior does not happen with other buttons with shortcuts
`F1` thru `F12`.

Is this a conflict with the existing interpretation of `Ctrl`+`Z`? If so, is
there an easy way to avoid that conflict? Maybe just setting the
ShortcutContext appropriately?


Answer: Clicking on the button will give it the keyboard focus, and, more importantly,
remove focus from any other widget which has the same shortcut set.

All of the editable input widgets (such as `QLineEdit`, `QTextEdit`, etc) have
hard-coded [default key
bindings](http://doc.qt.io/qt-5/qlineedit.html#details) for various actions,
including `Ctrl+Z` (which undoes the last action). If such a widget has the
keyboard focus, its shortcut will get priority over the one you set for the
button (and vice versa).

When more than one widget has the same shortcut, you can set an event-filter
and use `ShortcutOverride` to disambiguate them:

    
    
        self.lineEdit.installEventFilter(self)
        ...
    
    def eventFilter(self, source, event):
        if (event.type() == QtCore.QEvent.ShortcutOverride and
            event.modifiers() == QtCore.Qt.ControlModifier and
            event.key() == QtCore.Qt.Key_Z):
            # eat the shortcut on the line-edit
            return True
        return super(Window, self).eventFilter(source, event)
    

However, as a user, I really **hate** applications that do this kind of thing.
When I use a standard input widget, I expect to be able to use all the
standard keyboard bindings. If they don't work as expected, it just looks like
a bug.

