views:

139

answers:

2
A: 

Could you try reimplementing your contextMenu with the mouseRelease event instead?

void CompositeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
        if(event->button() == Qt::RightButton)
        {
            contextMenu->popup(QCursor::pos());
        }
}
Vicken Simonian
@Vicken SimonianDue to an advice I edited boundingRect code. I guess it is a neat idea to unite childs boundingRects. But this time item can' t catch events like contextmenuevent and mousepressevent. So my prior problem is to catch events. Do you have an idea what may cause this?
onurozcelik
A: 

I figured out that there may be two solutions for catching events. First one is reimplementing shape function. In my case it will be implemented like this.

QPainterPath shape() const
{
  QPainterPath path;
  path.addRect(boundingRect());
  return path;
}

Second one is to use QGraphicsItemGroup
It will be good idea to use QGraphicsItemGroup if you diretly adding your items to scene. But in my case I have to subclass QGraphicsItemGroup because of I am using a layout. So temporarily I choose writing my own item.

onurozcelik