• 8147阅读
  • 6回复

QGraphicsScene::mouseMoveEvent [复制链接]

上一主题 下一主题
离线jiang_198586
 

只看楼主 倒序阅读 楼主  发表于: 2010-04-29
— 本帖被 XChinux 从 General Qt Programming 移动到本区(2011-01-02) —
QGraphicsScene::mouseMoveEvent为什么只有在鼠标按下左键拖动时才有效,我想实现在QGraphicsScene直接鼠标拖动就能得到鼠标位置,那个怎么实现?
离线xtfllbl

只看该作者 1楼 发表于: 2010-04-29
mouseTracking : bool
This property holds whether mouse tracking is enabled for the widget.

If mouse tracking is disabled (the default), the widget only receives mouse move events when at least one mouse button is pressed while the mouse is being moved.

If mouse tracking is enabled, the widget receives mouse move events even if no buttons are pressed.

Access functions:

bool    hasMouseTracking () const
void    setMouseTracking ( bool enable )
See also mouseMoveEvent().
上海欢迎您
离线jiang_198586

只看该作者 2楼 发表于: 2010-04-29
QGraphicsScene类没有setMouseTracking ( bool enable )方法,而QWidget才有,所以不知怎么弄
离线xtfllbl

只看该作者 3楼 发表于: 2010-04-29
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.

When a QGraphicsView receives a QMouseEvent, it translates it to a QGraphicsSceneMouseEvent. The event is then forwarded to the QGraphicsScene associated with the view. If the event is not handled by the scene, the view may use it, e.g., for the DragMode.

In addition to containing the item, scene, and screen coordinates of the event (as pos(), scenePos(), and screenPos()), mouse events also contain the coordinates of the previous mouse event received by the view. These can be retrieved with lastPos(), lastScreenPos(), and lastScenePos().

See also QGraphicsSceneContextMenuEvent, QGraphicsSceneHoverEvent, QGraphicsSceneWheelEvent, and QMouseEvent.

多少有点关系,看看能不能找到其中的突破口。

静候佳音,解决了记得说下方法。
上海欢迎您
离线wu_java
只看该作者 4楼 发表于: 2011-07-23
如楼上所言,在view里添加setMouseTracking ( bool enable );将鼠标移动的信号传到scene里面来
离线hnwdx

只看该作者 5楼 发表于: 2011-07-24
引用第4楼wu_java于2011-07-23 14:25发表的  :
如楼上所言,在view里添加setMouseTracking ( bool enable );将鼠标移动的信号传到scene里面来


离线hnwdx

只看该作者 6楼 发表于: 2011-07-24
    viewport()->setMouseTracking(true);
快速回复
限100 字节
 
上一个 下一个