Qt 改变鼠标形状
Qt 改变鼠标形状(转载)
改变鼠标形状,在绘制坐标系的时候有用到,特此记下:
1 this->setMouseTracking(true); //设置为不按下鼠标键触发moveEvent 2 void mouseMoveEvent(QMouseEvent* event) 3 { 4 QPoint mousepos = event()->pos(); 5 6 //在坐标(0 ~ width,0 ~ height)范围内改变鼠标形状 7 if(mousepos.rx() > 0 8 && mousepos.rx() < width 9 && mousepos.ry() > 0 10 && mousepos.ry() < height) 11 { 12 this->setCursor(Qt::CrossCursor); 13 } 14 else 15 { 16 this->setCursor(Qt::ArrowCursor); //范围之外变回原来形状 17 } 18 }
鼠标形状对应的枚举值:
Qt::ArrowCursor
Qt::UpArrowCursor
Qt::CrossCursor
Qt::IBeamCursor
Qt::WaitCursor
Qt::BusyCursor
Qt::ForbiddenCursor
Qt::PointingHandCursor
Qt::WhatsThisCursor
Qt::SizeVerCursor
Qt::SizeHorCursor
Qt::SizeBDiagCursor
Qt::SizeFDiagCursor
Qt::SizeAllCursor
Qt::SplitVCursor
Qt::SplitHCursor
Qt::OpenHandCursor
Qt::ClosedHandCursor
Qt::BlankCursor
还可以自定义鼠标形状:
1 Qcurosr *myCursor=new QCursor(QPixmap(":/images/custom.png"),-1,-1); //-1,-1表示热点位于图片中心 2 this->setCursor(*myCursor);
原文链接:https://www.cnblogs.com/ybqjymy/p/13323916.html