Reputation: 12874
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.
Upvotes: 1
Views: 2639
Reputation: 38161
You messed up evrything.
QGraphicsScene
always process ALL mouse events! It is responsible for passing those events to its children (QGraphicsItem
s 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.
Upvotes: 1