1

I have a scene object derived from QGraphicsScene and custom item on it, derived from QGraphicsItem. I want this item be "transparent" for mouse events so clicking on the item area will call QGraphicsScene::mousePressEvent();

From the documentation:

"...To disable mouse events for an item (i.e., make it transparent for mouse events), call setAcceptedMouseButtons(0)."

But still the scene does not receive mouce events if I click on the item area.

MyItem::MyItem(QGraphicsItem * parent) :
    QGraphicsItem(parent)
{
    setAcceptedMouseButtons(Qt::NoButton);
}

QRectF MyItem::boundingRect() const
{
    return QRectF(0,0,100,100);
}

void MyItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
{
    painter->fillRect(boundingRect(),QColor(0,0,160,10));
}

So how can I ignore mouse events for the item?

It is possible then in the future I will need to process mouse events with the item so may be right decision is to implement QGraphicsItem::mousePressEvent() and just to pass somehow the event to the scene.

0

1 Answer 1

1

You messed up evrything. QGraphicsScene always process ALL mouse events! It is responsible for passing those events to its children (QGraphicsItems in scene). So scene receives mouse events then event is passed to respective item in scene.

So if item doesn't accept mouse event this doesn't mean the scene will process mouse event again.

It looks like that you messed up something when you did subclass a scene.

Bottom line your question is wrong.

1
  • Thanks @marek-r, you are totally right!! I've found this in the scene implementation: if(itemAt(mouseEvent->scenePos()) == NULL){...}.
    – folibis
    Mar 4, 2014 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.