Handle focus loss for cmd bar
This commit is contained in:
parent
7d285fa5a3
commit
08207d6f9d
@ -1,5 +1,5 @@
|
|||||||
from PyQt5.QtWidgets import QLineEdit, QHBoxLayout, QLabel, QWidget
|
from PyQt5.QtWidgets import QLineEdit, QHBoxLayout, QLabel, QWidget, QShortcut
|
||||||
from PyQt5.QtCore import pyqtSignal
|
from PyQt5.QtCore import pyqtSignal, Qt
|
||||||
from PyQt5.QtGui import QValidator
|
from PyQt5.QtGui import QValidator
|
||||||
|
|
||||||
class StatusBar(QWidget):
|
class StatusBar(QWidget):
|
||||||
@ -46,6 +46,12 @@ class StatusCommand(QLineEdit):
|
|||||||
self.setValidator(CmdValidator())
|
self.setValidator(CmdValidator())
|
||||||
self.returnPressed.connect(self.process_cmd)
|
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):
|
def process_cmd(self):
|
||||||
text = self.text().lstrip(':')
|
text = self.text().lstrip(':')
|
||||||
self.setText('')
|
self.setText('')
|
||||||
@ -55,6 +61,10 @@ class StatusCommand(QLineEdit):
|
|||||||
self.setText(text)
|
self.setText(text)
|
||||||
self.setFocus()
|
self.setFocus()
|
||||||
|
|
||||||
|
def focusOutEvent(self, event):
|
||||||
|
self.setText('')
|
||||||
|
super().focusOutEvent(event)
|
||||||
|
|
||||||
class CmdValidator(QValidator):
|
class CmdValidator(QValidator):
|
||||||
def validate(self, string, pos):
|
def validate(self, string, pos):
|
||||||
if string.startswith(':'):
|
if string.startswith(':'):
|
||||||
|
Loading…
Reference in New Issue
Block a user