admin管理员组文章数量:1278948
I'm using two items: 'ItemImage', which inherits QGraphicsItem, and 'ItemDrawing', which inherits QGraphicsPixmapItem.
Both items are created in mainwindow constructor, added scene with scene->addItem()
.
MyWindow::MyWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MyWindowClass())
, _scene(new QGraphicsScene(this))
, _item_drawing(new ItemDrawing())
, _item_image(new ItemImage())
{
...
_scene->addItem(_item_drawing);
_scene->addItem(_item_image);
ui->view->setScene(_scene);
}
and both items call setAcceptHoverEvents(true);
in their constructor, reimplement hoverEnterEvent
and hoverMoveEvent
,
also, I reimplemented mouseMoveEvent
of graphics view and called QGraphicsView::mouseMoveEvent
.
/* ItemImage */
ItemImage::ItemImage(QGraphicsItem* parent)
: QGraphicsItem(parent)
{
setAcceptHoverEvents(true);
setFlags(ItemIsSelectable | ItemIsMovable);
}
void ItemImage::hoverMoveEvent(QGraphicsSceneHoverEvent* event)
{
...
QGraphicsItem::hoverMoveEvent(event);
}
/* ItemDrawing */
ItemDrawing::ItemDrawing(QGraphicsItem* parent)
: QGraphicsPixmapItem(parent)
, _temp_measure()
{
setZValue(1);
setTransformationMode(Qt::SmoothTransformation);
setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
setAcceptHoverEvents(true);
}
void ItemDrawing::hoverMoveEvent(QGraphicsSceneHoverEvent* event)
{
...
QGraphicsItem::hoverMoveEvent(event);
}
/* GraphicsView which inherits QGraphicsView */
void GraphicsView::mouseMoveEvent(QMouseEvent* e)
{
...
QGraphicsView::mouseMoveEvent(e);
}
I want to receive hover...Event
on both items that are overlapping at the same coordinates.
For now, only the highest z-order item receives the event(i.e. ItemDrawing that called setZValue(1)
). If move the ItemImage out of the ItemDrawing, the ItemImage will also receive hover events.
If create one item as a child of another, both will be received hover events.
My question is, is there no other way to receive hover events on both items that are overlapping at the same coordinates?
I couldn't find anything in any documentation about propagating events between two items that don't have a common parent.
And I looked at Qt's implementation of QGraphicsScenePrivate::dispatchHoverEvent
, but it doesn't seem to propagate the event to all items positioned under the mouse.
So my conclusion is that it seems impossible for both items to receive events, but I'm not sure if I'm right or if I'm missing something.
本文标签: cQGraphicsSceneHoverEvent is only propagated top most QGraphicsItemStack Overflow
版权声明:本文标题:c++ - QGraphicsSceneHoverEvent is only propagated top most QGraphicsItem - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741252262a2366012.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论