Related To : PyQt 4.6.1
I am creating a QGraphicsTextItem by sub classing it. The code snippet is take from demo example. The item is working fine.
1. When I select the text and press delete, nothing happens, It's because in my QMainWindow there is an action with short cut:
action.setShortcut(QtGui.QKeySequence.Delete)
To copy to clipboard, switch view to plain text mode
This action is getting triggered. Any pointers to solve this?
Here is the code:
def __init__(self, parent=None, text=qx.Null):
super(QxTextItem, self).__init__(parent)
self.setHtml(text)
def itemChange(self, change, value):
self.selectedChange.emit(self)
return value
def focusOutEvent(self, event):
self.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)
self.lostFocus.emit(self)
super(QxTextItem, self).focusOutEvent(event)
def mouseDoubleClickEvent(self, event):
if self.textInteractionFlags() == QtCore.Qt.NoTextInteraction:
self.setTextInteractionFlags(QtCore.Qt.TextEditorInteraction)
super(QxTextItem, self).mouseDoubleClickEvent(event)
class QxTextItem(QtGui.QGraphicsTextItem):
lostFocus = QtCore.pyqtSignal(QtGui.QGraphicsTextItem)
selectedChange = QtCore.pyqtSignal(QtGui.QGraphicsItem)
def __init__(self, parent=None, text=qx.Null):
super(QxTextItem, self).__init__(parent)
self.setFlag(QtGui.QGraphicsItem.ItemIsMovable)
self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable)
self.setHtml(text)
def itemChange(self, change, value):
if change == QtGui.QGraphicsItem.ItemSelectedChange:
self.selectedChange.emit(self)
return value
def focusOutEvent(self, event):
self.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)
self.lostFocus.emit(self)
super(QxTextItem, self).focusOutEvent(event)
def mouseDoubleClickEvent(self, event):
if self.textInteractionFlags() == QtCore.Qt.NoTextInteraction:
self.setTextInteractionFlags(QtCore.Qt.TextEditorInteraction)
super(QxTextItem, self).mouseDoubleClickEvent(event)
To copy to clipboard, switch view to plain text mode
Bookmarks