I'm trying to use QShortcut to set a keyboard shortcut, only for when a
certain widget is focused.

I thought that by setting the parent, this would work. For example:

QtGui.QShortcut(QtGui.QKeySequence("Ctrl+Return"), self.myWidget,
self.doSomething)

But, this is fired when ever Ctrl+Return is pressed. I know I can do this
by subclassing QWidget and overwriting setShortcut, but this seems overkill?

Is there an easier way?

I think this can be done using QShortcutContext
http://pyqt.sourceforge.net/Docs/PyQt4/qshortcut.html but

QtGui.QShortcut(QtGui.QKeySequence("Ctrl+Return"), self.myWidget,
self.doSomething, context=QtCore.Qt.WidgetShortcut)

doesn't work either.

Thanks,
Joseph David Borġ
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to