Answer the question
In order to leave comments, you need to log in
How to close a PyQt window with a hotkey combination?
Let's say we have a normal window:
import sys
from PyQt4 import QtGui, QtCore
class Wind(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setWindowFlags(QtCore.Qt.FramelessWindowHint|QtCore.Qt.Tool)
self.setGeometry(300, 300, 250, 150)
def close_window(self):
self.close()
quit()
app = QtGui.QApplication(sys.argv)
icon = Wind()
icon.show()
sys.exit(app.exec_())
Answer the question
In order to leave comments, you need to log in
with active window
def keyPressEvent(self, e):
if int(e.modifiers()) == (QtCore.Qt.ControlModifier +
QtCore.Qt.AltModifier +
QtCore.Qt.ShiftModifier):
if e.key() == QtCore.Qt.Key_Q:
self.close_window()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question