【问题标题】:QGraphicsItem and hover eventQGraphicsItem 和悬停事件
【发布时间】:2015-09-20 12:05:50
【问题描述】:

我重新实现了 hoverEnterEvent 但由于某种原因它没有被调用:-( 此时我的方法很简单:

void LinteItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event) {

    qDebug("Mouse hovered");
    QGraphicsItem::hoverEnterEvent(event);
}

我在视图上设置了 mouseTracking。我可以使用 mouseMove 等放置新的 LinteItem,因此我知道跟踪工作正常。

我在构造函数中有以下内容:

setFlags(QGraphicsItem::ItemIsSelectable |
             QGraphicsItem::ItemIsMovable |
             QGraphicsItem::ItemSendsGeometryChanges);     
setAcceptHoverEvents(true);

知道为什么我没有收到这些事件吗? 我正在使用 Qt 5.5 顺便说一句

【问题讨论】:

    标签: qt mousehover


    【解决方案1】:

    如果您的覆盖自定义 QGraphicsView 鼠标事件处理程序调用基类的原始处理程序,它应该可以工作,例如

    void CustomGraphicsView::mouseMoveEvent(QMouseEvent *event)
    {
        // do something...
    
        // send the event to graphics scene and items
        QGraphicsView::mouseMoveEvent(event);
    }
    

    【讨论】:

    • 谢谢,是的。它确实:-)
    猜你喜欢
    • 2011-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-12
    相关资源
    最近更新 更多