mouseTracking:bool
Qt Assistant 解释:
该属性用来设置某个控件是否被跟踪轨迹。
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.
如果该属性设置fasle,这个控件就算正在移动,也仅仅只有鼠标pressed按下之后,才会接受鼠标移动事件。
If mouse tracking is enabled, the widget receives mouse move events even if no buttons are pressed.
如果该属性是true,就算该按钮不被按下,它也会一直接受鼠标移动的事件。
所以想要实现mouseMoveEvent,若是setMouseTrack(true),直接可以得到监听事件。若是setMouseTrack(false),只有鼠标按下才会有mouseMove监听事件响应。
1 ....
2
3 test.widget.setMouseTrack(true);
4
5 ....
6
7 /**
8
9 * @brief 鼠标滑动事件
10
11 */
12
13 void TestWidget::mouseMoveEvent(QMouseEvent* event)
14
15 {
16
17 QPoint m = event->globalPos();
18
19 ui.lblMouseEventGlobalPos->setText(QString("(%1,%2)").arg(m.x()).arg(m.y()));
20
21 QPoint n = QCursor::pos();
22
23 ui.lblCursorPos->setText(QString("(%1,%2)").arg(m.x()).arg(m.y()));
24
25
26
27 }