QT学习小结之鼠标事件-创新互联
qt鼠标事件所包含的头文件
鼠标事件常见的有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);
}
}
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
当前标题:QT学习小结之鼠标事件-创新互联
网页路径:http://azwzsj.com/article/cdgjsp.html