PDA

View Full Version : QGraphicsTextItem and paint event



prashant
6th November 2009, 07:52
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)

This action is getting triggered. Any pointers to solve this?

Here is the code:


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.NoTextInter action)
self.lostFocus.emit(self)
super(QxTextItem, self).focusOutEvent(event)

def mouseDoubleClickEvent(self, event):
if self.textInteractionFlags() == QtCore.Qt.NoTextInteraction:
self.setTextInteractionFlags(QtCore.Qt.TextEditorI nteraction)
super(QxTextItem, self).mouseDoubleClickEvent(event)