PDA

View Full Version : Unable to have 2 QGraphicsView getting their own events



EarthHobbit
18th April 2015, 11:53
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);

And the double click event of the QGraphicsTextItem:

void myQGraphicsTextItemClass::mouseDoubleClickEvent(QG raphicsSceneMouseEvent *evt)
{
setTextInteractionFlags(Qt::TextEditorInteraction) ;
QGraphicsTextItem::mouseDoubleClickEvent(evt);
}

and my class definition:

class myQGraphicsTextItemClass : public QGraphicsTextItem
{
Q_OBJECT
public:
myQGraphicsTextItemClass(int nb,QString text, int parentWidthReceived, QGraphicsItem *parent=0);
virtual ~myQGraphicsTextItemClass() {};
protected:
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *evt);
};

Thanks !

anda_skoa
18th April 2015, 12:45
I have 1 main QGraphicsView, that has 2 QGraphicsView children.

Why?

Cheers,
_

EarthHobbit
18th April 2015, 13:10
I am writing a node editor. Each node is represented by a QGraphicsView. I can potentially have 20 QGraphicsView children or more.
And the name of the node is displayed on it using a QGraphicsTextItem (must be editable).

Added after 10 minutes:

The issue is even actually the same with 2 QGraphicsTextItem in the same QGraphicsView.

wysota
18th April 2015, 15:36
Each node is represented by a QGraphicsView.

Why?

Cheers,
_

EarthHobbit
18th April 2015, 17:16
It makes it easier to drag, as I use it as a placeholder for multiple elements.

wysota
18th April 2015, 17:35
What makes it easier to drag than a QGraphicsItem?

EarthHobbit
18th April 2015, 20:02
I don't know. Being new to Qt this what I did. Let me check the QGraphicsItem.