1. 重写窗体的鼠标事件方法时,需要在窗体构造函数中添加如下代码,设置窗体追踪鼠标
setMouseTracking(true);
2. mousePressEvent(QMouseEvent* e):鼠标按下事件响应函数
void 项目名::mousePressEvent(QMouseEvent* e)
{
if(Qt::LeftButton == e->button()) //左键
{
}
else if(Qt::RightButton == e->button()) //右键
{
}
else if(Qt::MidButton == e->button()) //中键
{
}
}