<div dir="ltr"><div><div>Hi.<br></div>Can any kindly soul help me  grok the QShortcuts with PyQt5?  I'd like to make a keyboard shortcut to a Python function (not a QMenu action). I'm really not getting this. All the tutorials and manuals I've found are PyQt4, and as such do not work. The C++ documentation is not helping me get any closer. <br><br>1. I have a PyQt5 widget, for which I'd like to run "myfunction" after a keyboard shortcut. <br><br>2. In the UI file, call it "MyWidget_Ui.py", the main class we'll call "SearchWidget".<br><br>3. in SearchWidget "__init__", I have something like "self.shortcut = QShortcut(QKeySequence("Ctrl+O"), self)". <br><br></div>Execution results in error: <br><div style="margin-left:40px">self.shortcut = QShortcut(QKeySequence("Ctrl+O"), self)<br>NameError: name 'QShortcut' is not defined<br></div><div><br>I'm very confused by the "app" and "window" and "ui" separation. I'm not clear which one is supposed to get the QShortcut.<br><br>Questions:<br>1. Where am I supposed to put "QShortcut"?  Does it go in the Ui file __init__? <br></div><div>2. How/from where do I import QShortcut class? <br></div><div><br><br>"main"() looks like this:<br>    app = QtWidgets.QApplication(sys.argv)<br>    window = QtWidgets.QWidget()<br><br>    ui = MyWidget()<br>    ui.setupUi(window)    <br><br>    window.show()<br><div><div><br>Thanks greatly<br></div><div>- Matt<br></div></div></div></div>