qt鼠标事件所包含的头文件
专业从事网站建设、网站设计,高端网站制作设计,成都微信小程序,网站推广的成都做网站的公司。优秀技术团队竭力真诚服务,采用html5+CSS3前端渲染技术,响应式网站设计,让网站在手机、平板、PC、微信下都能呈现。建站过程建立专项小组,与您实时在线互动,随时提供解决方案,畅聊想法和感受。
鼠标事件常见的有mousePressEvent(),mouseReleaseEvent(),mouseDoubleClickEvent(),mouseMoveEvent(),下面我就贴上几段代码吧
void Event_test::mouseMoveEvent(QMouseEvent *event) //鼠标拖动事件
{
QPoint point;
point = QCursor::pos();
qDebug()<<"point"<
qDebug()<<"move :"<<" "<pos().x()<<" "< pos().y();
}
void Event_test::mousePressEvent(QMouseEvent *event) //鼠标按下事件
{
QString str="("+QString::number(event->x())+","+QString::number(event->y())+")";
if(event->button()==Qt::LeftButton)
{
statusBar()->showMessage (tr("Mouse Left Button Pressed:")+str);//在状态栏中显示临时信息
}
else if(event->button()==Qt::RightButton)
{
statusBar()->showMessage (tr("Mouse Right Button Pressed:")+str);
}
else if(event->button()==Qt::MidButton)
{
statusBar()->showMessage (tr("Mouse Middle Button Pressed:")+str);
}
qDebug()<<"Press "<<" "<pos().x()<<" "< pos().y();
}
void Event_test::mouseReleaseEvent(QMouseEvent *event) //鼠标释放事件
{
QString str="("+QString::number(event->x())+","+QString::number(event->y())+")";
statusBar()->showMessage (tr("Mouser Released:")+str,3000);
qDebug()<<"release "<<" "<pos().x()<<" "< pos().y();
}
void Event_test::mouseDoubleClickEvent(QMouseEvent *event) //鼠标双击事件
{
QString str="("+QString::number(event->x())+","+QString::number(event->y())+")";
if(event->button()==Qt::LeftButton)
{
statusBar()->showMessage (tr("Mouse Left Button Double Clicked:")+str);
}
else if(event->button()==Qt::RightButton)
{
statusBar()->showMessage (tr("Mouse Right Button Double Clicked:")+str);
}
else if(event->button()==Qt::MidButton)
{
statusBar()->showMessage (tr("Mouse Middle Button Double Clicked:")+str);
}
}