PDA

View Full Version : QGraphicsTextItem always gets focus once clicked



EarthHobbit
18th April 2015, 13:58
I have a QGraphicsView containing a custom QGraphicsTextItem. The QGraphicsTextItem has a double-click event:


void myQGraphicsTextItemClass::mouseDoubleClickEvent(QG raphicsSceneMouseEvent *evt)
{
MGlobal::displayInfo(MQtUtil::toMString(QString(). sprintf("Double click on textId")));

QGraphicsTextItem::mouseDoubleClickEvent(evt);
}
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);
and my QGraphicsTextItem class looks like:


class myQGraphicsTextItemClass : public QGraphicsTextItem
{
Q_OBJECT
public:
myQGraphicsTextItemClass(QGraphicsItem *parent=0);
virtual ~myQGraphicsTextItemClass() {};
protected:
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *evt);
};
and its constructor:


myQGraphicsTextItemClass::myQGraphicsTextItemClass (QGraphicsItem *parent) : QGraphicsTextItem ( parent )
{
setPlainText("Hello");
setTextInteractionFlags(Qt::TextEditorInteraction) ;
}
Thanks.

wysota
20th April 2015, 07:35
Please provide a minimal compilable example reproducing the problem.