Created
December 20, 2012 13:49
-
-
Save hahastudio/4345418 to your computer and use it in GitHub Desktop.
A TextEdit editor that sends editingFinished events when the text was changed and focus is lost.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt4 import QtCore, QtGui | |
class TextEdit(QtGui.QTextEdit): | |
""" | |
A TextEdit editor that sends editingFinished events | |
when the text was changed and focus is lost. | |
""" | |
editingFinished = QtCore.pyqtSignal() | |
receivedFocus = QtCore.pyqtSignal() | |
def __init__(self, parent): | |
super(TextEdit, self).__init__(parent) | |
self._changed = False | |
self.setTabChangesFocus( True ) | |
self.textChanged.connect( self._handle_text_changed ) | |
def focusInEvent(self, event): | |
super(TextEdit, self).focusInEvent( event ) | |
self.receivedFocus.emit() | |
def focusOutEvent(self, event): | |
if self._changed: | |
self.editingFinished.emit() | |
super(TextEdit, self).focusOutEvent( event ) | |
def _handle_text_changed(self): | |
self._changed = True | |
def setTextChanged(self, state=True): | |
self._changed = state | |
def setHtml(self, html): | |
QtGui.QTextEdit.setHtml(self, html) | |
self._changed = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment