QT笔记- QGraphicsView视图- setAcceptHoverEvents()设置开启鼠标悬停事件

阅读 206

2022-02-15

说明

开启鼠标悬停事件意味着当鼠标悬停在该item下时,可由hoverMoveEvent()函数接收到鼠标的移动事件。开启方法: setAcceptHoverEvents(true)。

函数

  1. void QGraphicsItem::setAcceptHoverEvents(bool enabled)
  2. virtual void QGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent * event)

释义

  1. 设置接受悬停事件。enabled设置为true,意味着接收悬停事件。否则不接受。
  2. 悬停移动事件。重新实现该函数,并且设置setAcceptHoverEvents(true)时,可接收悬停移动事件。通过函数event->pos()可获得鼠标在当前item中的坐标。

示例

        略。

精彩评论(0)

0 0 举报