I have a QGraphicsView containing a custom QGraphicsTextItem. The QGraphicsTextItem has a double-click event:
{
MGlobal
::displayInfo(MQtUtil
::toMString(QString().
sprintf("Double click on textId")));
}
void myQGraphicsTextItemClass::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *evt)
{
MGlobal::displayInfo(MQtUtil::toMString(QString().sprintf("Double click on textId")));
QGraphicsTextItem::mouseDoubleClickEvent(evt);
}
To copy to clipboard, switch view to plain text mode
What goes well:
When I double click in the QGraphicsView but not in the QGraphicsTextItem, then nothing happens, which is normal. When I double click directly on the QGraphicsTextItem, then I get a "Double click on textId" message, as expected.
What goes wrong:
However when I then double click again wherever on my main QGraphicsView but not in the QGraphicsTextItem, then I always get the above message.
Question:
How come the QGraphicsTextItem keeps getting the mouseDoubleClickEvent events even if I am not directly clicking on it ?
My QGraphicsTextItem is created this way from the QGraphicsView constructor:
oneTextNode=new myQGraphicsTextItemClass();
scene()->addItem(oneTextNode);
oneTextNode=new myQGraphicsTextItemClass();
scene()->addItem(oneTextNode);
To copy to clipboard, switch view to plain text mode
and my QGraphicsTextItem class looks like:
{
Q_OBJECT
public:
virtual ~myQGraphicsTextItemClass() {};
protected:
};
class myQGraphicsTextItemClass : public QGraphicsTextItem
{
Q_OBJECT
public:
myQGraphicsTextItemClass(QGraphicsItem *parent=0);
virtual ~myQGraphicsTextItemClass() {};
protected:
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *evt);
};
To copy to clipboard, switch view to plain text mode
and its constructor:
{
setPlainText("Hello");
setTextInteractionFlags(Qt::TextEditorInteraction);
}
myQGraphicsTextItemClass::myQGraphicsTextItemClass(QGraphicsItem *parent) : QGraphicsTextItem ( parent )
{
setPlainText("Hello");
setTextInteractionFlags(Qt::TextEditorInteraction);
}
To copy to clipboard, switch view to plain text mode
Thanks.
Bookmarks