I have 1 main QGraphicsView, that has 2 QGraphicsView children. Each of the children has one custom QGraphicsTextItem.
When I double click on one of the QGraphicsTextItems (whatever the one I am clicking on), I can type letters and they appear properly in it.
When I then double click the other QGraphicsTextItem, the first one gets the double-click event and the letters.
If I restart my app and first click on the second QGraphicsTextItem, then the first one will never get focus.
How can I ensure that the one I am clicking on gets the events ?
That's the code in each of the QGraphicsView children:
myQGraphicsTextItemClass *oneTextNode
oneTextNode=new myQGraphicsTextItemClass(newNodeId,nodeName,this->geometry().width());
oneTextNode->setPos(10,30);
scene()->addItem(oneTextNode);
myQGraphicsTextItemClass *oneTextNode
oneTextNode=new myQGraphicsTextItemClass(newNodeId,nodeName,this->geometry().width());
oneTextNode->setPos(10,30);
scene()->addItem(oneTextNode);
To copy to clipboard, switch view to plain text mode
And the double click event of the QGraphicsTextItem:
{
setTextInteractionFlags(Qt::TextEditorInteraction);
}
void myQGraphicsTextItemClass::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *evt)
{
setTextInteractionFlags(Qt::TextEditorInteraction);
QGraphicsTextItem::mouseDoubleClickEvent(evt);
}
To copy to clipboard, switch view to plain text mode
and my class definition:
{
Q_OBJECT
public:
virtual ~myQGraphicsTextItemClass() {};
protected:
};
class myQGraphicsTextItemClass : public QGraphicsTextItem
{
Q_OBJECT
public:
myQGraphicsTextItemClass(int nb,QString text, int parentWidthReceived, QGraphicsItem *parent=0);
virtual ~myQGraphicsTextItemClass() {};
protected:
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *evt);
};
To copy to clipboard, switch view to plain text mode
Thanks !
Bookmarks