From 08207d6f9d2c0bd63bfef12b2f476b4b3f5942b7 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 17 Jan 2014 07:18:48 +0100 Subject: [PATCH] Handle focus loss for cmd bar --- qutebrowser/widgets/statusbar.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/qutebrowser/widgets/statusbar.py b/qutebrowser/widgets/statusbar.py index 43486ca03..58e113192 100644 --- a/qutebrowser/widgets/statusbar.py +++ b/qutebrowser/widgets/statusbar.py @@ -1,5 +1,5 @@ -from PyQt5.QtWidgets import QLineEdit, QHBoxLayout, QLabel, QWidget -from PyQt5.QtCore import pyqtSignal +from PyQt5.QtWidgets import QLineEdit, QHBoxLayout, QLabel, QWidget, QShortcut +from PyQt5.QtCore import pyqtSignal, Qt from PyQt5.QtGui import QValidator class StatusBar(QWidget): @@ -46,6 +46,12 @@ class StatusCommand(QLineEdit): self.setValidator(CmdValidator()) self.returnPressed.connect(self.process_cmd) + # FIXME this does not work + self.esc = QShortcut(self) + self.esc.setKey(Qt.Key_Escape) + self.esc.setContext(Qt.WidgetWithChildrenShortcut) + self.esc.activated.connect(parent.setFocus) + def process_cmd(self): text = self.text().lstrip(':') self.setText('') @@ -55,6 +61,10 @@ class StatusCommand(QLineEdit): self.setText(text) self.setFocus() + def focusOutEvent(self, event): + self.setText('') + super().focusOutEvent(event) + class CmdValidator(QValidator): def validate(self, string, pos): if string.startswith(':'):