mouse events handling with QGraphicsItem
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);"
Code:
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();
}
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:
Code:
{
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");
}
}
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
Re: mouse events handling with QGraphicsItem
I am not using grabMouse like you did
but what I read about that is that on widget at a time can grab the mouse.
So I am afraid that you can't do what you want that way.
Re: mouse events handling with QGraphicsItem
Quote:
Originally Posted by
scascio
I am not using grabMouse like you did
but what I read about that is that on widget at a time can grab the mouse.
So I am afraid that you can't do what you want that way.
Yes, I've just found the problem :)
grabMouse cannot be used, you're right, but my problem was in boundingRect method.
I returned:
and this of course means that the buttons are 0 sized.
Now I return:
and everything works fine :D
Thanks anyway.
Re: mouse events handling with QGraphicsItem
I've forgotten on thing:
If these flags are not set, it doesn't work !
O at least ItemIsSelectable I think.