Hallo all,
I have a strange problem with the mouse events handling in QGraphicsView and QGraphicsItem.
I create a:
"class MyGraphicsView : public QGraphicsView"
that has a function called:
"void addButton (tButtonValues& vals);"
void MyGraphicsView::addButton(tButtonValues& vals)
{
MyButton* btn = new MyButton(vals, MyFrame::GetFrame(vals.Owner));
vals.MySelf = btn;
if (vals.Owner < 0) // the button has no owner so it has not been added to the scene yet
m_Scene->addItem(btn);
btn->grabMouse();
}
void MyGraphicsView::addButton(tButtonValues& vals)
{
MyButton* btn = new MyButton(vals, MyFrame::GetFrame(vals.Owner));
vals.MySelf = btn;
if (vals.Owner < 0) // the button has no owner so it has not been added to the scene yet
m_Scene->addItem(btn);
btn->grabMouse();
}
To copy to clipboard, switch view to plain text mode
The problem is that I add 16 buttons to the view but only the last one grabs the mouse.
In MyButton class I have this method:
{
printf("mouse RELEASE event - <%i> - <%i>\n", event->pos().toPoint().x(), event->pos().toPoint().y() );
QRect r
( mVals.
qpPosition, mVals.
qsSize );
if ( r.contains(event->pos().toPoint()) )
{
puts("OK");
}
}
void MyButton::mouseReleaseEvent ( QGraphicsSceneMouseEvent* event )
{
printf("mouse RELEASE event - <%i> - <%i>\n", event->pos().toPoint().x(), event->pos().toPoint().y() );
QRect r( mVals.qpPosition, mVals.qsSize );
if ( r.contains(event->pos().toPoint()) )
{
puts("OK");
}
QGraphicsItem::mouseReleaseEvent(event);
}
To copy to clipboard, switch view to plain text mode
I try to propagate the event to all the other items with a mouseReleaseEvent call but no way, only the last created button gets the call.
Is it a bug or am I doing something wrong ?
Thanks
Bookmarks